file_handler
util.file_handler
IMAGE_EXTENSION
module-attribute
ZstdFileHandler
ZstdFileHandler is a utility class for handling the compression and decompression of data using the Zstandard (Zstd) compression algorithm. This class provides static methods to save and load data in a compressed format using Zstd and pickle for serialization.
save_compressed_data
staticmethod
Compresses and saves any Python data object to a file.
This method serializes the given data object using pickle, compresses the serialized data using Zstd, and writes the compressed data to a file.
Parameters:
-
data(Any) –The Python data object to be compressed and saved.
-
file_path(str) –The path of the file where the compressed data will be stored. If the file already exists, it will be overwritten.
Returns:
-
None–None
Raises:
-
FileNotFoundError–If the specified file path is not valid.
-
PicklingError–If the data object cannot be serialized.
-
ZstdError–If compression fails.
Source code in SaigeToolkit/util/file_handler.py
load_compressed_data
staticmethod
Loads and decompresses data from a file.
This method reads compressed data from a file, decompresses it using Zstd, and then deserializes it using pickle to convert it back to the original Python data object.
Parameters:
-
file_path(str) –The path of the file from which the compressed data is to be read. The file must exist and contain valid compressed data.
Returns:
-
Any(Any) –The original Python data object that was compressed and saved in the file.
Raises:
-
FileNotFoundError–If the specified file path does not exist.
-
UnpicklingError–If the decompressed data cannot be deserialized.
-
ZstdError–If decompression fails.
Source code in SaigeToolkit/util/file_handler.py
glob_files
glob_files(root_path: str, extensions: Tuple[str], recursive: bool = True, skip_hidden_directories: bool = True, max_directories: Optional[int] = None, max_files: Optional[int] = None, relative_path: bool = False) -> Tuple[List[str], bool, bool]
glob files with specified extensions
Parameters:
-
root_path(str) –description
-
extensions(Tuple[str]) –description
-
recursive(bool, default:True) –description. Defaults to True.
-
skip_hidden_directories(bool, default:True) –description. Defaults to True.
-
max_directories(Optional[int], default:None) –max number of directories to search. Defaults to None.
-
max_files(Optional[int], default:None) –max file number limit. Defaults to None.
-
relative_path(bool, default:False) –description. Defaults to False.
Returns:
-
Tuple[List[str], bool, bool]–Tuple[List[str], bool, bool]: description