Package: centopy
centopyAPI for managing files in a specified folder.Installation$pipinstallcentopyUsageFilesManagerTo use the FilesManager class in your Python script or project, import it as follows:fromcentopyimportFilesManagerCreating a FilesManager InstanceTo create an instance of the FilesManager class, provide the folder path where you want to manage the files:folder_path="/path/to/folder"file_manager=FilesManager(folder_path)Saving and Loading FilesYou can save and load file contents using the save_file and load_file methods, respectively:file_name="example.txt"file_contents="Hello, world!"# Save file contents to the specified filefile_manager.save_file(file_name,file_contents)# Load file contents from the specified fileloaded_contents=file_manager.load_file(file_name)Reading and Writing FilesYou can also directly read from and write content to files using the read_file and write_file methods:file_name="example.txt"file_contents="Hello, world!"# Write contents to the specified filefile_manager.write_file(file_name,file_contents)# Read contents from the specified fileread_contents=file_manager.read_file(file_name)Handling File StatesThe FilesManager class keeps track of the state of each file that has been saved or loaded. You can check the state of a file using the get_file_state method:file_name="example.txt"state=file_manager.get_file_state(file_name)print(f"File state for '{file_name}':{state}")Note:The state is represented as a list of events. For example, if a file is saved and loaded, the state attribute (file_manager.file_state[file_name]) will be["saved", "loaded"].Handling ExceptionsWhen loading a file, if the specified file is not found, the load_file method returns None and logs an error message using the logging module. To handle such cases, you can check if the loaded contents are None:file_name="nonexistent_file.txt"loaded_contents=file_manager.load_file(file_name)ifloaded_contentsisNone:print(f"The file '{file_name}' was not found.")Compressor:The classcentopy.Compressoris an api to thezipfile.ZipFilecontext manager. You can use a custom extension when instantiating.Writing and appending filesarchive=centopy.Compressor('file',extension='customzip',wdir='data')An objectcentopy.Compressorhas a attribute as an instance ofcentopy.FilesManager.print(archive.manager.list_files())['file.customzip','data.bin','hello.txt']content='Hello, centopy!'archive.write('hello.txt',content=content)# list files inside archiveprint(archive.namelist())['hello.txt']Binary Data Compression# Create a Compressor objectcompressor=Compressor("bin_archive")# Write binary content to a new file and add it to the archivebinary_data=b'\x00\x01\x02\x03\x04'compressor.writeb("binary_data.bin",binary_data)# Append binary content to an existing file in the archivenew_binary_data=b'\x05\x06\x07'compressor.appendb("binary_data.bin",new_binary_data)# Read the binary content of a file from the archivebinary_content=compressor.read("binary_data.bin",as_text=False)print("Binary content:",binary_content)ContributingInterested in contributing? Check out the contributing guidelines. Please note that this project is released with a Code of Conduct. By contributing to this project, you agree to abide by its terms.Licensecentopywas created by Vagner Bessa. Vagner Bessa retains all rights to the source and it may not be reproduced, distributed, or used to create derivative works.Creditscentopywas created withcookiecutterand thepy-pkgs-cookiecuttertemplate.