pybit7z package¶
Copyright (c) 2024 l.feng. All rights reserved.
pybit7z: A wrapper based on bit7z.
- class pybit7z.ArchiveStartOffset¶
Bases:
pybind11_objectOffset from where the archive starts within the input file.
Members:
NoneOffset : Don’t specify an archive start offset. For some formats like Zip archives this means that the whole input file will be searched for the archive’s start.
FileStart : Check only the file start for the archive’s start.
- FileStart = <ArchiveStartOffset.FileStart: 1>¶
- NoneOffset = <ArchiveStartOffset.NoneOffset: 0>¶
- ArchiveStartOffset.name -> str
- property value¶
- class pybit7z.Bit7zLibrary¶
Bases:
pybind11_objectThe Bit7zLibrary class allows accessing the basic functionalities provided by the 7z DLLs.
- get_codec_paths(self: pybit7z._core.Bit7zLibrary) list[str]¶
Returns the file paths of all external codec DLLs currently loaded.
- Returns:
A list of strings with the paths of the loaded codec DLLs.
- get_codecs(self: pybit7z._core.Bit7zLibrary) list[pybit7z._core.BitCodecInfo]¶
Enumerates all compression codecs (methods) supported by the loaded 7-zip library.
- Returns:
A list of BitCodecInfo describing each supported codec.
- get_external_in_format(self: pybit7z._core.Bit7zLibrary, name: str) object¶
Returns the read-only archive format (BitInFormat) for the given external format name.
- Parameters:
name – the name of the external format (as returned by get_formats).
- Returns:
A BitInFormat instance, or None if the format was not found.
- get_external_in_out_format(self: pybit7z._core.Bit7zLibrary, name: str) object¶
Returns the read-write archive format (BitInOutFormat) for the given external format name.
- Parameters:
name – the name of the external format (as returned by get_formats).
- Returns:
A BitInOutFormat instance, or None if the format was not found.
- get_formats(self: pybit7z._core.Bit7zLibrary) list[pybit7z._core.BitFormatInfo]¶
Enumerates all archive formats supported by the loaded 7-zip library.
- Returns:
A list of BitFormatInfo describing each supported format.
- load_plugins(self: pybit7z._core.Bit7zLibrary, plugin_paths: list[str]) bool¶
Loads external codec and format DLLs from the given folders and registers them with the 7-zip library.
Follows the official 7-Zip LoadCodecs.cpp flow: for each supplied folder the Codecs subfolder is scanned first, then the Formats subfolder. Every DLL is inspected for both codec exports and format-handler exports, so a single DLL can supply both codecs and archive handlers.
Multiple folders can be supplied; they are scanned in order and the results are accumulated.
- Parameters:
plugin_paths – a list of paths to the folders containing the Codecs/ and Formats/ subfolders.
- Returns:
True if at least one codec or format was successfully loaded, False otherwise.
- use_large_pages(self: pybit7z._core.Bit7zLibrary) None¶
Enable large page mode for 7zip library. This can improve performance on some systems.
- class pybit7z.Bit7zLibraryLoader¶
Bases:
pybind11_objectThe Bit7zLibraryLoader class provides deferred and optional loading of the 7-zip shared library.
Unlike Bit7zLibrary which loads the shared library in its constructor, Bit7zLibraryLoader allows constructing an empty loader and loading the library at a later time. It also supports unloading and reloading the library as well as non-throwing error handling.
- is_loaded(self: pybit7z._core.Bit7zLibraryLoader) bool¶
Whether a 7-zip shared library is currently loaded.
- library(self: pybit7z._core.Bit7zLibraryLoader) pybit7z._core.Bit7zLibrary¶
Returns a reference to the loaded Bit7zLibrary.
- Returns:
a const reference to the underlying Bit7zLibrary.
- Raises:
BitException – if no library is currently loaded.
- load(self: pybit7z._core.Bit7zLibraryLoader, library_path: str) None¶
Loads the specified 7-zip shared library.
If a library is already loaded it is unloaded first.
- Parameters:
library_path – the path to the 7-zip shared library to be loaded.
- try_load(self: pybit7z._core.Bit7zLibraryLoader, library_path: str) bool¶
Loads the specified 7-zip shared library without throwing on failure.
If a library is already loaded it is unloaded first.
- Parameters:
library_path – the path to the 7-zip shared library to be loaded.
- Returns:
True if the loading succeeded, False otherwise.
- unload(self: pybit7z._core.Bit7zLibraryLoader) None¶
Unloads the currently loaded library if any.
- class pybit7z.BitAbstractArchiveCreator¶
Bases:
BitAbstractArchiveHandlerAbstract class representing a generic archive creator.
- compression_format(self: pybit7z._core.BitAbstractArchiveCreator) pybit7z._core.BitInOutFormat¶
the format used for creating/updating an archive.
- compression_method(self: pybit7z._core.BitAbstractArchiveCreator) pybit7z._core.BitCompressionMethod¶
the compression method used for creating/updating an archive.
- crypt_headers(self: pybit7z._core.BitAbstractArchiveCreator) bool¶
whether the creator crypts also the headers of archives or not.
- dictionary_size(self: pybit7z._core.BitAbstractArchiveCreator) int¶
the dictionary size used for creating/updating an archive.
- set_compression_level(self: pybit7z._core.BitAbstractArchiveCreator, level: object) None¶
Sets the compression level to be used when creating/updating an archive.
- Parameters:
level – the compression level desired. Can be a BitCompressionLevel enum value or an integer.
- set_compression_method(self: pybit7z._core.BitAbstractArchiveCreator, method: pybit7z._core.BitCompressionMethod) None¶
Sets the compression method to be used when creating/updating an archive.
- Parameters:
method – the compression method desired.
- set_dictionary_size(self: pybit7z._core.BitAbstractArchiveCreator, dictionary_size: int) None¶
Sets the dictionary size to be used when creating/updating an archive.
- Parameters:
dictionary_size – the dictionary size desired.
- set_format_property(self: pybit7z._core.BitAbstractArchiveCreator, name: str, value: pybit7z._core.BitPropVariant) None¶
Sets a property for the output archive format as described by the 7-zip documentation(e.g., https://sevenzip.osdn.jp/chm/cmdline/switches/method.htm).
For example, passing the string L”tm” with a false value while creating a .7z archive will disable storing the last modified timestamps of the compressed files.
- Parameters:
name – the name of the property to be set.
value – the value to be used for the property.
- set_password(*args, **kwargs)¶
Overloaded function.
set_password(self: pybit7z._core.BitAbstractArchiveCreator, password: str) -> None
Sets up a password for the output archives.
When setting a password, the produced archives will be encrypted using the default cryptographic method of the output format. The option “crypt headers” remains unchanged, in contrast with what happens when calling the set_password(tstring, bool) method.
- Parameters:
password – the password to be used when creating/updating archives.
Note
Calling set_password when the output format doesn’t support archive encryption (e.g., GZip, BZip2, etc…) does not have any effects (in other words, it doesn’t throw exceptions, and it has no effects on compression operations). After a password has been set, it will be used for every subsequent operation. To disable the use of the password, you need to call the clearPassword method (inherited from BitAbstractArchiveHandler), which is equivalent to set_password(“”).
set_password(self: pybit7z._core.BitAbstractArchiveCreator, password: str, scope: pybit7z._core.EncryptionScope) -> None
Sets up a password for the output archive.
When setting a password, the produced archive will be encrypted using the default cryptographic method of the output format. If the format is 7z, and the option “cryptHeaders” is set to true, the headers of the archive will be encrypted, resulting in a password request every time the output file will be opened.
- Parameters:
password – the password to be used when creating/updating archives.
scope – the scope of encryption; use EncryptionScope::DataAndHeaders to also encrypt the archive headers (valid only for the 7z format).
Note
Calling set_password when the output format doesn’t support archive encryption (e.g., GZip, BZip2, etc…) does not have any effects (in other words, it doesn’t throw exceptions, and it has no effects on compression operations). Calling set_password with “cryptHeaders” set to true does not have effects on formats different from 7z. After a password has been set, it will be used for every subsequent operation. To disable the use of the password, you need to call the clearPassword method (inherited from BitAbstractArchiveHandler), which is equivalent to set_password(“”).
- set_solid_mode(self: pybit7z._core.BitAbstractArchiveCreator, solid_mode: bool) None¶
Sets whether the archive creator uses solid compression or not.
- Parameters:
solid_mode – the solid mode desired.
Note
Setting the solid compression mode to true has effect only when using the 7z format with multiple input files.
- set_store_creation_time(self: pybit7z._core.BitAbstractArchiveCreator, store_creation_time: bool) None¶
Sets whether the creator will store creation timestamps of items.
- Parameters:
store_creation_time – if true, creation timestamps of items will be stored in the output archive.
- set_store_last_access_time(self: pybit7z._core.BitAbstractArchiveCreator, store_last_access_time: bool) None¶
Sets whether the creator will store last access timestamps of items.
- Parameters:
store_last_access_time – if true, last access timestamps of items will be stored in the output archive.
- set_store_last_write_time(self: pybit7z._core.BitAbstractArchiveCreator, store_last_write_time: bool) None¶
Sets whether the creator will store last write timestamps of items.
- Parameters:
store_last_write_time – if false, last write timestamps will be omitted from the output archive.
By default, all archive formats store last write timestamps; pass false to suppress them.
- set_store_open_files(self: pybit7z._core.BitAbstractArchiveCreator, store_open_files: bool) None¶
Sets whether the creator will attempt to compress files that are locked by other processes. When enabled, the creator opens files with shared read/write access on Windows, which is equivalent to 7-zip’s -ssw switch. This allows compressing files that another process has open for writing.
Warning
Compressing a file that is actively being written by another process may produce an incomplete or inconsistent archive entry.
Note
On non-Windows platforms this setting has no effect.
- Parameters:
store_open_files – if true, the creator will attempt to compress files open by other processes.
- set_store_symbolic_links(self: pybit7z._core.BitAbstractArchiveCreator, store_symbolic_links: bool) None¶
Sets whether the creator will store symbolic links as links in the output archive.
- Parameters:
store_symbolic_links – if true, symbolic links will be stored as links.
- set_threads_count(self: pybit7z._core.BitAbstractArchiveCreator, threads_count: int) None¶
Sets the number of threads to be used when creating/updating an archive.
- Parameters:
threads_count – the number of threads desired.
- set_update_mode(self: pybit7z._core.BitAbstractArchiveCreator, mode: pybit7z._core.UpdateMode) None¶
Sets whether and how the creator can update existing archives or not.
- Parameters:
mode – the desired update mode.
Note
If set to UpdateMode::None, a subsequent compression operation may throw an exception if it targets an existing archive.
- set_volume_size(self: pybit7z._core.BitAbstractArchiveCreator, volume_size: int) None¶
Sets the volumeSize (in bytes) of the output archive volumes.
- Parameters:
volume_size – The dimension of a volume.
Note
This setting has effects only when the destination archive is on the filesystem.
- set_word_size(self: pybit7z._core.BitAbstractArchiveCreator, word_size: int) None¶
Sets the word size to be used when creating/updating an archive.
- Parameters:
word_size – the word size desired.
- solid_mode(self: pybit7z._core.BitAbstractArchiveCreator) bool¶
whether the archive creator uses solid compression or not.
- store_creation_time(self: pybit7z._core.BitAbstractArchiveCreator) bool¶
true if the creator has been explicitly configured to store creation timestamps of items.
- store_last_access_time(self: pybit7z._core.BitAbstractArchiveCreator) bool¶
true if the creator has been explicitly configured to store last access timestamps of items.
- store_last_write_time(self: pybit7z._core.BitAbstractArchiveCreator) bool¶
true if the creator has been explicitly configured to store last write timestamps of items.
- store_open_files(self: pybit7z._core.BitAbstractArchiveCreator) bool¶
whether the creator will attempt to compress files that are locked by other processes.
- store_symbolic_links(self: pybit7z._core.BitAbstractArchiveCreator) bool¶
whether the archive creator stores symbolic links as links in the output archive.
- threads_count(self: pybit7z._core.BitAbstractArchiveCreator) int¶
the number of threads used when creating/updating an archive (a 0 value means that it will use the 7-zip default value).
- update_mode(self: pybit7z._core.BitAbstractArchiveCreator) pybit7z._core.UpdateMode¶
the update mode used when updating existing archives.
- volume_size(self: pybit7z._core.BitAbstractArchiveCreator) int¶
the volume size (in bytes) used when creating multi-volume archives (a 0 value means that all files are going in a single archive).
- word_size(self: pybit7z._core.BitAbstractArchiveCreator) int¶
the word size used for creating/updating an archive.
- class pybit7z.BitAbstractArchiveHandler¶
Bases:
pybind11_objectAbstract class representing a generic archive handler.
- clear_password(self: pybit7z._core.BitAbstractArchiveHandler) None¶
Clear the current password used by the handler.
Calling clear_password() will disable the encryption/decryption of archives.
Note
This is equivalent to calling set_password(“”).
- file_callback(self: pybit7z._core.BitAbstractArchiveHandler) Callable[[str], None]¶
the current file callback.
- format(self: pybit7z._core.BitAbstractArchiveHandler) pybit7z._core.BitInFormat¶
the format used by the handler for extracting or compressing.
- is_password_defined(self: pybit7z._core.BitAbstractArchiveHandler) bool¶
a boolean value indicating whether a password is defined or not.
- overwrite_mode(self: pybit7z._core.BitAbstractArchiveHandler) pybit7z._core.OverwriteMode¶
the overwrite mode.
- password(self: pybit7z._core.BitAbstractArchiveHandler) str¶
the password used to open, extract, or encrypt the archive.
- password_callback(self: pybit7z._core.BitAbstractArchiveHandler) Callable[[], str]¶
the current password callback.
- progress_callback(self: pybit7z._core.BitAbstractArchiveHandler) Callable[[int], bool]¶
the current progress callback.
- ratio_callback(self: pybit7z._core.BitAbstractArchiveHandler) Callable[[int, int], None]¶
the current ratio callback.
- retainDirectories(self: pybit7z._core.BitAbstractArchiveHandler) bool¶
a boolean value indicating whether the directory structure must be preserved while extracting or compressing the archive.
- set_file_callback(self: pybit7z._core.BitAbstractArchiveHandler, callback: Callable[[str], None]) None¶
Sets the function to be called when the current file being processed changes.
- Parameters:
callback – the file callback to be used.
- set_overwrite_mode(self: pybit7z._core.BitAbstractArchiveHandler, mode: pybit7z._core.OverwriteMode) None¶
Sets how the handler should behave when it tries to output to an existing file or buffer. :param mode: the OverwriteMode to be used by the handler.
- set_password(self: pybit7z._core.BitAbstractArchiveHandler, password: str) None¶
Sets up a password to be used by the archive handler.
The password will be used to encrypt/decrypt archives by using the default cryptographic method of the archive format.
- Parameters:
password – the password to be used.
Note
Calling this set_password when the input archive is not encrypted does not have any effect on the extraction process. Calling this set_password when the output format doesn’t support archive encryption (e.g., GZip, BZip2, etc…) does not have any effects (in other words, it doesn’t throw exceptions, and it has no effects on compression operations). After a password has been set, it will be used for every subsequent operation. To disable the use of the password, you need to call the clear_password method, which is equivalent to calling set_password(L””).
- set_password_callback(self: pybit7z._core.BitAbstractArchiveHandler, callback: Callable[[], str]) None¶
Sets the function to be called when a password is needed to complete the ongoing operation.
- Parameters:
callback – the password callback to be used.
- set_progress_callback(self: pybit7z._core.BitAbstractArchiveHandler, callback: Callable[[int], bool]) None¶
Sets the function to be called when the processed size of the ongoing operation is updated.
- Parameters:
callback – the progress callback to be used.
Note
The completion percentage of the current operation can be obtained by calculating int((100.0 * processed_size) / total_size).
- set_ratio_callback(self: pybit7z._core.BitAbstractArchiveHandler, callback: Callable[[int, int], None]) None¶
Sets the function to be called when the input processed size and current output size of the ongoing operation are known.
- Parameters:
callback – the ratio callback to be used.
Note
The ratio percentage of a compression operation can be obtained by calculating int((100.0 * output_size) / input_size).
- set_retain_directories(self: pybit7z._core.BitAbstractArchiveHandler, retain: bool) None¶
Sets whether the operations’ output will preserve the input’s directory structure or not.
- Parameters:
retain – the setting for preserving or not the input directory structure
- set_total_callback(self: pybit7z._core.BitAbstractArchiveHandler, callback: Callable[[int], None]) None¶
Sets the function to be called when the total size of an operation is available.
- Parameters:
callback – the total callback to be used.
- total_callback(self: pybit7z._core.BitAbstractArchiveHandler) Callable[[int], None]¶
the current total callback.
- class pybit7z.BitAbstractArchiveOpener¶
Bases:
BitAbstractArchiveHandler- extraction_format(self: pybit7z._core.BitAbstractArchiveOpener) pybit7z._core.BitInFormat¶
the archive format used by the archive opener.
- class pybit7z.BitArchiveEditor¶
Bases:
BitArchiveWriter- apply_changes(self: pybit7z._core.BitArchiveEditor) None¶
Applies the requested changes (i.e., rename/update/delete operations) to the input archive.
- delete_item(*args, **kwargs)¶
Overloaded function.
delete_item(self: pybit7z._core.BitArchiveEditor, index: int, policy: pybit7z._core.DeletePolicy = DeletePolicy.ItemOnly) -> None
Marks as deleted the item at the given index.
- Parameters:
index – the index of the item to be deleted.
policy – the policy to be used when deleting items. Default to DeletePolicy.ItemOnly.
- Exceptions:
BitException if the index is invalid.
Note
By default, if the item is a folder, only its metadata is deleted, not the files within it. If instead the policy is set to DeletePolicy::RecurseDirs, then the items within the folder will also be deleted.
delete_item(self: pybit7z._core.BitArchiveEditor, item_path: str, policy: pybit7z._core.DeletePolicy = DeletePolicy.ItemOnly) -> None
Marks as deleted the archive’s item(s) with the specified path.
- Parameters:
item_path – the path (in the archive) of the item to be deleted.
policy – the policy to be used when deleting items. Default to DeletePolicy.ItemOnly.
- Exceptions:
BitException if the specified path is empty or invalid, or if no matching item could be found.
Note
By default, if the marked item is a folder, only its metadata will be deleted, not the files within it. To delete the folder contents as well, set the policy to DeletePolicy::RecurseDirs. The specified path must not begin with a path separator. A path with a trailing separator will _only_ be considered if the policy is DeletePolicy::RecurseDirs, and will only match folders; with DeletePolicy::ItemOnly, no item will match a path with a trailing separator. Generally, archives may contain multiple items with the same paths. If this is the case, all matching items will be marked as deleted according to the specified policy.
- rename_item(*args, **kwargs)¶
Overloaded function.
rename_item(self: pybit7z._core.BitArchiveEditor, index: int, new_path: str) -> None
Requests to change the path of the item at the specified index with the given one.
- Parameters:
index – the index of the item to be renamed.
new_path – the new path of the item.
rename_item(self: pybit7z._core.BitArchiveEditor, old_path: str, new_path: str) -> None
Requests to change the path of the item from oldPath to the newPath.
- Parameters:
old_path – the current path of the item to be renamed.
new_path – the new path of the item.
- set_update_mode(self: pybit7z._core.BitArchiveEditor, update_mode: pybit7z._core.UpdateMode) None¶
Sets how the editor performs the update of the items in the archive.
- Parameters:
mode – the desired update mode (either UpdateMode::Append or UpdateMode::Overwrite).
Note
BitArchiveEditor doesn’t support UpdateMode::Nothing.
- update_item(*args, **kwargs)¶
Overloaded function.
update_item(self: object, index: int, input_buffer: bytes) -> None
Requests to update the content of the item at the specified index with the data from the given buffer.
- Parameters:
index – the index of the item to be updated.
input_buffer – the buffer containing the new data for the item.
update_item(self: pybit7z._core.BitArchiveEditor, index: int, in_file: str) -> None
Requests to update the content of the item at the specified index with the data from the given file.
- Parameters:
index – the index of the item to be updated.
in_file – the path of the file to be used for the update.
update_item(self: object, item_path: str, input_buffer: bytes) -> None
Requests to update the content of the item at the specified path with the data from the given buffer.
- Parameters:
item_path – the path of the item to be updated.
input_buffer – the buffer containing the new data for the item.
update_item(self: pybit7z._core.BitArchiveEditor, item_path: str, in_file: str) -> None
Requests to update the content of the item at the specified path with the data from the given file.
- Parameters:
item_path – the path of the item to be updated.
in_file – the path of the file to be used for the update.
- class pybit7z.BitArchiveItem¶
Bases:
BitGenericItemThe BitArchiveItem class represents a generic item inside an archive.
- attributes(self: pybit7z._core.BitArchiveItem) int¶
the item attributes.
- crc(self: pybit7z._core.BitArchiveItem) int¶
the CRC of the item.
- creation_time(self: pybit7z._core.BitArchiveItem) datetime.datetime¶
- extension(self: pybit7z._core.BitArchiveItem) str¶
the extension of the item, if available or if it can be inferred from the name; otherwise it returns an empty string (e.g., when the item is a folder).
- index(self: pybit7z._core.BitArchiveItem) int¶
the index of the item in the archive.
- is_encrypted(self: pybit7z._core.BitArchiveItem) bool¶
true if and only if the item is encrypted.
- last_access_time(self: pybit7z._core.BitArchiveItem) datetime.datetime¶
- last_write_time(self: pybit7z._core.BitArchiveItem) datetime.datetime¶
- native_name(self: pybit7z._core.BitArchiveItem) str¶
Same as name() but returning a native string (i.e. std::wstring on Windows, std::string elsewhere).
- native_path(self: pybit7z._core.BitArchiveItem) str¶
the path of the item in the archive, if available or inferable from the name, or an empty string otherwise.
- pack_size(self: pybit7z._core.BitArchiveItem) int¶
the compressed size of the item.
- raw_path(self: pybit7z._core.BitArchiveItem) str¶
Same as path() but returning the internal string type used by 7-Zip on all OSes (wide string).
- class pybit7z.BitArchiveItemInfo¶
Bases:
BitArchiveItemThe BitArchiveItemInfo class represents an archived item and that stores all its properties for later use.
- item_properties(self: pybit7z._core.BitArchiveItemInfo) dict[pybit7z._core.BitProperty, pybit7z._core.BitPropVariant]¶
a map of all the available (i.e., non-empty) item properties and their respective values.
- item_property(self: pybit7z._core.BitArchiveItemInfo, arg0: pybit7z._core.BitProperty) pybit7z._core.BitPropVariant¶
Gets the specified item property.
- Parameters:
property_id (bit7z::BitProperty) – The ID of the property to get.
- Returns:
the value of the item property, if available, or an empty BitPropVariant.
- Return type:
- class pybit7z.BitArchiveItemOffset¶
Bases:
BitArchiveItemThe BitArchiveItemOffset class represents an archived item but doesn’t store its properties.
- item_property(self: pybit7z._core.BitArchiveItemOffset, arg0: pybit7z._core.BitProperty) pybit7z._core.BitPropVariant¶
Gets the specified item property.
- Parameters:
property_id (bit7z::BitProperty) – The ID of the property to get.
- Returns:
the value of the item property, if available, or an empty BitPropVariant.
- Return type:
- class pybit7z.BitArchiveReader¶
Bases:
BitAbstractArchiveOpener,BitInputArchive- archive_properties(self: pybit7z._core.BitArchiveReader) dict[pybit7z._core.BitProperty, pybit7z._core.BitPropVariant]¶
a map of all the available (i.e., non-empty) archive properties and their respective values.
- files_count(self: pybit7z._core.BitArchiveReader) int¶
the number of files in the archive.
- folders_count(self: pybit7z._core.BitArchiveReader) int¶
the number of folders in the archive.
- has_encrypted_items(self: pybit7z._core.BitArchiveReader) bool¶
true if and only if the archive has at least one encrypted item.
- is_encrypted(self: pybit7z._core.BitArchiveReader) bool¶
true if and only if the archive has only encrypted items.
- static is_header_encrypted(*args, **kwargs)¶
Overloaded function.
is_header_encrypted(library: pybit7z._core.Bit7zLibrary, in_archive: bytes, format: pybit7z._core.BitInFormat = FormatAuto) -> bool
Checks if the given memory buffer archive is header-encrypted or not.
- Parameters:
library – the library used for decompression.
in_archive – the input buffer containing the archive to be checked.
format – the format of the input archive. Default is FormatAuto.
is_header_encrypted(library: pybit7z._core.Bit7zLibrary, in_archive: str, format: pybit7z._core.BitInFormat = FormatAuto) -> bool
Checks if the given archive is header-encrypted or not.
- Parameters:
library – the library used for decompression.
in_archive – the path to the archive to be checked.
format – the format of the input archive. Default is FormatAuto.
- is_multi_volume(self: pybit7z._core.BitArchiveReader) bool¶
true if and only if the archive is composed by multiple volumes.
- is_solid(self: pybit7z._core.BitArchiveReader) bool¶
true if and only if the archive was created using solid compression.
- items(self: pybit7z._core.BitArchiveReader) list[pybit7z._core.BitArchiveItemInfo]¶
the list of all the archive items as BitArchiveItem objects.
- items_matching(self: pybit7z._core.BitArchiveReader, pattern: str) list[pybit7z._core.BitArchiveItemInfo]¶
Gets the items whose paths match the given wildcard pattern.
- Parameters:
pattern – a wildcard pattern used for matching the paths of items inside the archive.
- Returns:
the items whose paths match the given wildcard pattern.
- pack_size(self: pybit7z._core.BitArchiveReader) int¶
the total compressed size of the archive content.
- size(self: pybit7z._core.BitArchiveReader) int¶
the total uncompressed size of the archive content.
- volumes_count(self: pybit7z._core.BitArchiveReader) int¶
the number of volumes in the archive.
- class pybit7z.BitArchiveWriter¶
- class pybit7z.BitCodecInfo¶
Bases:
pybind11_objectInformation about a compression codec (method) supported by the 7-zip library.
- property decoder¶
- property description¶
- property encoder¶
- property id¶
- property is_external¶
- property is_filter¶
- property name¶
- property pack_streams¶
- property unpack_streams¶
- class pybit7z.BitCompressionLevel¶
Bases:
pybind11_objectCompression level for 7zip library
Members:
Nothing
Fastest
Fast
Normal
Max
Ultra
- Fast = <BitCompressionLevel.Fast: 3>¶
- Fastest = <BitCompressionLevel.Fastest: 1>¶
- Max = <BitCompressionLevel.Max: 7>¶
- Normal = <BitCompressionLevel.Normal: 5>¶
- Nothing = <BitCompressionLevel.Nothing: 0>¶
- Ultra = <BitCompressionLevel.Ultra: 9>¶
- BitCompressionLevel.name -> str
- property value¶
- class pybit7z.BitCompressionMethod¶
Bases:
pybind11_objectCompression method by bit7z when creating archives.
Members:
Copy
Deflate
Deflate64
BZip2
Lzma
Lzma2
Ppmd
- BZip2 = <BitCompressionMethod.BZip2: 3>¶
- Copy = <BitCompressionMethod.Copy: 0>¶
- Deflate = <BitCompressionMethod.Deflate: 1>¶
- Deflate64 = <BitCompressionMethod.Deflate64: 2>¶
- Lzma = <BitCompressionMethod.Lzma: 4>¶
- Lzma2 = <BitCompressionMethod.Lzma2: 5>¶
- Ppmd = <BitCompressionMethod.Ppmd: 6>¶
- BitCompressionMethod.name -> str
- property value¶
- class pybit7z.BitFileCompressor¶
Bases:
BitStringCompressor- compress(*args, **kwargs)¶
Overloaded function.
compress(self: pybit7z._core.BitFileCompressor, in_files: list[str], out_archive: str) -> None
Compresses the given files or directories.
The items in the first argument must be the relative or absolute paths to files or directories existing on the filesystem.
- Parameters:
in_files – the input files to be compressed.
out_archive – the path (relative or absolute) to the output archive file.
compress(self: pybit7z._core.BitFileCompressor, in_files: dict[str, str], out_archive: str) -> None
Compresses the given files or directories using the specified aliases.
The items in the first argument must be the relative or absolute paths to files or directories existing on the filesystem. Each pair in the map must follow the following format: {“path to file in the filesystem”, “alias path in the archive”}.
- Parameters:
in_files – a map of paths and corresponding aliases.
out_archive – the path (relative or absolute) to the output archive file.
- compress_directory(self: pybit7z._core.BitFileCompressor, in_dir: str, out_archive: str) None¶
Compresses an entire directory.
- Parameters:
in_dir – the path (relative or absolute) to the input directory.
out_archive – the path (relative or absolute) to the output archive file.
Note
This method is equivalent to compress_files with filter set to “”.
- compress_directory_contents(self: pybit7z._core.BitFileCompressor, in_dir: str, out_archive: str, recursive: bool = True, filter_pattern: str = '*') None¶
Compresses the contents of a directory.
- Parameters:
in_dir – the path (relative or absolute) to the input directory.
out_archive – the path (relative or absolute) to the output archive file.
recursive – (optional) if true, it searches files inside the sub-folders of in_dir.
filter_pattern – the wildcard pattern to filter the files to be compressed (optional).
Note
Unlike compress_files, this method includes also the metadata of the sub-folders.
- compress_files(*args, **kwargs)¶
Overloaded function.
compress_files(self: pybit7z._core.BitFileCompressor, in_files: list[str], out_archive: str) -> None
Compresses a group of files.
- Parameters:
in_files – the input files to be compressed.
out_archive – the path (relative or absolute) to the output archive file.
Note
Any path to a directory or to a not-existing file will be ignored!
compress_files(self: pybit7z._core.BitFileCompressor, in_dir: str, out_archive: str, recursive: bool = True, filter_pattern: str = ‘*’) -> None
Compresses all the files in the given directory.
- Parameters:
in_dir – the path (relative or absolute) to the input directory.
out_archive – the path (relative or absolute) to the output archive file.
recursive – (optional) if true, it searches files inside the sub-folders of in_dir.
filter_pattern – the wildcard pattern to filter the files to be compressed (optional).
- pybit7z.BitFileExtractor¶
alias of
BitStringExtractor
- class pybit7z.BitFormatInfo¶
Bases:
pybind11_objectInformation about an archive format supported by the 7-zip library.
- property add_extension¶
- property extension¶
- property flags¶
- property name¶
- property signature¶
- property signature_offset¶
- property update¶
- class pybit7z.BitGenericItem¶
Bases:
pybind11_objectThe BitGenericItem interface class represents a generic item (either inside or outside an archive).
- attributes(self: pybit7z._core.BitGenericItem) int¶
the item attributes.
- is_dir(self: pybit7z._core.BitGenericItem) bool¶
true if and only if the item is a directory (i.e., it has the property BitProperty::IsDir)
- name(self: pybit7z._core.BitGenericItem) str¶
the name of the item, if available or inferable from the path, or an empty string otherwise.
- path(self: pybit7z._core.BitGenericItem) str¶
the path of the item.
- size(self: pybit7z._core.BitGenericItem) int¶
the uncompressed size of the item.
- class pybit7z.BitInFormat¶
Bases:
pybind11_objectThe BitInFormat class specifies an extractable archive format.
- value(self: pybit7z._core.BitInFormat) int¶
the value of the format in the 7z SDK.
- class pybit7z.BitInOutFormat¶
Bases:
BitInFormatThe BitInOutFormat class specifies a format available for creating new archives and extract old ones.
- default_method(self: pybit7z._core.BitInOutFormat) pybit7z._core.BitCompressionMethod¶
the default method used for compressing the archive format.
- extension(self: pybit7z._core.BitInOutFormat) str¶
the default file extension of the archive format.
- features(self: pybit7z._core.BitInOutFormat) pybit7z._core.FormatFeatures¶
the bitset of the features supported by the format.
- has_feature(self: pybit7z._core.BitInOutFormat, arg0: pybit7z._core.FormatFeatures) bool¶
Checks if the format has a specific feature (see FormatFeatures enum) :param feature: the feature to check :type feature: FormatFeatures
- Returns:
a boolean value indicating whether the format has the given feature.
- Return type:
- class pybit7z.BitInputArchive¶
Bases:
pybind11_object- archive_has_path(self: pybit7z._core.BitInputArchive) bool¶
Whether the archive has a path (i.e. filesystem archive) or not (e.g. buffer archive).
- archive_path(self: pybit7z._core.BitInputArchive) str¶
the path to the archive (the empty string for buffer/stream archives).
- archive_property(self: pybit7z._core.BitInputArchive, arg0: pybit7z._core.BitProperty) pybit7z._core.BitPropVariant¶
Gets the specified archive property.
- Parameters:
property – the property to be retrieved.
- Returns:
the current value of the archive property or an empty BitPropVariant if no value is specified.
- contains(self: pybit7z._core.BitInputArchive, path: str) bool¶
Find if there is an item in the archive that has the given path.
- Parameters:
path – the path of the file or folder to be checked.
- Returns:
true if and only if the archive contains the specified file or folder.
- detected_format(self: pybit7z._core.BitInputArchive) pybit7z._core.BitInFormat¶
the detected format of the file.
- extract_folder_to(self: pybit7z._core.BitInputArchive, out_dir: str, regex: str, policy: pybit7z._core.FolderPathPolicy = FolderPathPolicy.Strip) None¶
Extracts a folder from the archive to the chosen directory.
- Parameters:
out_dir – the output directory where the extracted files will be put.
regex – the regex used for matching the paths of files inside the archive.
policy – (optional) the filtering policy to be applied to the matching items.
- extract_matching_to(*args, **kwargs)¶
Overloaded function.
extract_matching_to(self: pybit7z._core.BitInputArchive, out_dir: str, item_filter: str, policy: pybit7z._core.FilterPolicy = FilterPolicy.Include) -> None
Extracts to the output directory all the items whose paths match the given wildcard pattern.
- Parameters:
out_dir – the output directory where the extracted files will be put.
item_filter – the wildcard pattern used for matching the paths of items inside the archive.
policy – (optional) the filtering policy to be applied to the matching items.
extract_matching_to(self: pybit7z._core.BitInputArchive, out_dir: str, regex: str, policy: pybit7z._core.FilterPolicy = FilterPolicy.Include) -> None
Extracts to the output directory all the items whose paths match the given regex pattern.
- Parameters:
out_dir – the output directory where the extracted files will be put.
regex – the regex used for matching the paths of files inside the archive.
policy – (optional) the filtering policy to be applied to the matching items.
- extract_root_folder_content_to(self: pybit7z._core.BitInputArchive, out_dir: str) None¶
Extracts the content of the archive’s root folder to the chosen directory. .. note:
The archive's root folder is the single top-level folder shared by all the items in the archive; its name is stripped from the extracted items' paths. If the archive does not have a single root folder, a BitException is thrown.
- Parameters:
out_dir – the output directory where the root folder’s content will be put.
- extract_to(*args, **kwargs)¶
Overloaded function.
extract_to(self: pybit7z._core.BitInputArchive, out_dir: str, indices: list[int] = []) -> None
Extracts the specified items to the chosen directory.
- Parameters:
out_dir – the output directory where the extracted files will be put.
indices – (optional) the indices of the files in the archive that must be extracted.
extract_to(self: pybit7z._core.BitInputArchive, out_dir: str, filter_callback: Callable[[pybit7z._core.BitArchiveItem], pybit7z._core.FilterResult]) -> None
Extracts to the output directory all the items that satisfy the given filtering criteria.
- Parameters:
out_dir – the output directory where the extracted files will be put.
filter_callback – the filtering callback that specifies whether to extract an item or not.
extract_to(self: pybit7z._core.BitInputArchive, out_dir: str, rename_callback: Callable[[pybit7z._core.BitArchiveItem], str]) -> None
Extracts the archive to the chosen directory, specifying the names of the extracted items via a RenameCallback. .. note:
The callback receives the archive item being extracted and must return the path that the extracted item must have on the filesystem. If the path of the item must not change, simply return the item's path in the callback. If the item must not be extracted, return an empty string in the callback.
- Parameters:
out_dir – the output directory where the extracted files will be put.
rename_callback – the callback that returns the names for the extracted files.
extract_to(self: pybit7z._core.BitInputArchive, index: int) -> bytes
Extracts a file to the output buffer.
- Parameters:
index – the index of the file to be extracted.
extract_to(self: pybit7z._core.BitInputArchive) -> dict[str, bytes]
Extracts the content of the archive to a map of memory buffers, where the keys are the paths of the files (inside the archive), and the values are their decompressed contents.
- is_item_encrypted(self: pybit7z._core.BitInputArchive, index: int) bool¶
Whether the item at the given index is encrypted.
- Parameters:
index – the index of an item in the archive.
- Returns:
true if and only if the item at the given index is encrypted.
- is_item_folder(self: pybit7z._core.BitInputArchive, index: int) bool¶
Whether the item at the given index is a folder. :param index: the index of an item in the archive.
- Returns:
true if and only if the item at the given index is a folder.
- item_at(self: pybit7z._core.BitInputArchive, index: int) pybit7z._core.BitArchiveItemOffset¶
Retrieve the item at the given index.
- Parameters:
index – the index of the item to be retrieved.
- Returns:
the item at the given index within the archive.
- item_has_property(self: pybit7z._core.BitInputArchive, index: int, property: pybit7z._core.BitProperty) bool¶
Checks whether the item at the given index has the specified property.
- Parameters:
index – the index (in the archive) of the item.
property – the property to be checked for existence.
- Returns:
true if the item has the property, false otherwise.
- item_property(self: pybit7z._core.BitInputArchive, index: int, property: pybit7z._core.BitProperty) pybit7z._core.BitPropVariant¶
Gets the specified item property.
- Parameters:
index – the index of the item to retrieve the property from.
property – the property to be retrieved.
- Returns:
the current value of the item property or an empty BitPropVariant if no value is specified.
- items_count(self: pybit7z._core.BitInputArchive) int¶
the number of items in the archive.
- root_folder(self: pybit7z._core.BitInputArchive) str¶
Returns the single top-level folder that contains all of the archive’s items.
The archive is considered to have a root folder only when every item is contained within the same top-level folder. There is no common root folder if the items belong to different top-level folders, if the archive contains a file at its root, or if the archive is empty.
- Returns:
the name of the archive’s root folder, or an empty string if the archive does not have a single common root folder.
- test(self: pybit7z._core.BitInputArchive, indices: list[int] = []) None¶
Tests the archive without extracting its content.
- Throws:
BitException: if the archive is not valid.
- Parameters:
indices – (optional) the indices of the items to be tested.
- test_item(self: pybit7z._core.BitInputArchive, index: int) None¶
Tests the item at the given index inside the archive without extracting it.
If the archive is not valid, or there’s no item at the given index, a BitException is thrown!
- use_format_property(self: pybit7z._core.BitInputArchive, name: str, property: pybit7z._core.BitPropVariant) None¶
Use the given format property to read the archive. See <https://github.com/rikyoz/bit7z/issues/248> for more information.
- Parameters:
name – the name of the property.
property – the property value.
- class pybit7z.BitInputItem¶
Bases:
pybind11_object- attributes(self: pybit7z._core.BitInputItem) int¶
the filesystem attributes of the item.
- has_new_data(self: pybit7z._core.BitInputItem) bool¶
true if the item contributes new data to the archive.
- in_archive_path(self: pybit7z._core.BitInputItem) str¶
the path of the item as it will be stored inside the archive.
- is_dir(self: pybit7z._core.BitInputItem) bool¶
true if the item represents a directory.
- is_sym_link(self: pybit7z._core.BitInputItem) bool¶
true if the item represents a symbolic link.
- item_property(self: pybit7z._core.BitInputItem, property: pybit7z._core.BitProperty) pybit7z._core.BitPropVariant¶
Returns the value of the given property for this item.
- path(self: pybit7z._core.BitInputItem) str¶
the native filesystem path of the item.
- set_creation_time(self: pybit7z._core.BitInputItem, creation_time: datetime.datetime) None¶
Sets the creation time of the item.
- set_last_access_time(self: pybit7z._core.BitInputItem, last_access_time: datetime.datetime) None¶
Sets the last access time of the item.
- set_last_write_time(self: pybit7z._core.BitInputItem, last_write_time: datetime.datetime) None¶
Sets the last write time of the item.
- size(self: pybit7z._core.BitInputItem) int¶
the uncompressed size of the item, in bytes.
- class pybit7z.BitMemCompressor¶
Bases:
BitAbstractArchiveCreator- compress_file(*args, **kwargs)¶
Overloaded function.
compress_file(self: pybit7z._core.BitMemCompressor, input: bytes, out_file: str, input_name: str = ‘’) -> None
Compresses the given memory buffer to the chosen archive.
- Parameters:
input – the input memory buffer to be compressed.
out_file – the path (relative or absolute) to the output archive file.
input_name – (optional) the name to give to the compressed file inside the output archive.
compress_file(self: pybit7z._core.BitMemCompressor, input: bytes, input_name: str = ‘’) -> bytes
Compresses the given memory buffer to a memory buffer.
- Parameters:
input – the input memory buffer to be compressed.
input_name – (optional) the name to give to the compressed file inside the output archive.
- class pybit7z.BitMemExtractor¶
Bases:
BitAbstractArchiveOpener- extract(*args, **kwargs)¶
Overloaded function.
extract(self: pybit7z._core.BitMemExtractor, in_archive: bytes, out_dir: str) -> None
Extracts the given archive to the chosen directory.
- Parameters:
in_archive – the input archive to be extracted.
out_dir – the directory where to extract the files.
extract(self: pybit7z._core.BitMemExtractor, in_archive: bytes, index: int) -> bytes
Extracts the specified item from the given archive to a memory buffer.
extract(self: pybit7z._core.BitMemExtractor, in_archive: bytes) -> dict[str, bytes]
Extracts all the items from the given archive to a dictionary of memory buffers.
- extract_items(self: pybit7z._core.BitMemExtractor, in_archive: bytes, indices: list[int], out_dir: str = '') None¶
Extracts the specified items from the given archive to the chosen directory.
- Parameters:
in_archive – the input archive to extract from.
indices – the indices of the files in the archive that should be extracted.
out_dir – the output directory where the extracted files will be placed.
- extract_matching(*args, **kwargs)¶
Overloaded function.
extract_matching(self: pybit7z._core.BitMemExtractor, in_archive: bytes, pattern: str, out_dir: str = ‘’, policy: pybit7z._core.FilterPolicy = FilterPolicy.Include) -> None
Extracts the files in the archive that match the given wildcard pattern to the chosen directory.
- Parameters:
in_archive – the input archive to be extracted.
pattern – the wildcard pattern to be used for matching the files.
out_dir – the directory where to extract the matching files.
policy – the filtering policy to be applied to the matched items. Default is FilterPolicy.Include.
extract_matching(self: pybit7z._core.BitMemExtractor, in_archive: bytes, pattern: str, policy: pybit7z._core.FilterPolicy = FilterPolicy.Include) -> bytes
Extracts to the output buffer the first file in the archive matching the given wildcard pattern. :param in_archive: the input archive to extract from. :param pattern: the wildcard pattern to be used for matching the files. :param policy: the filtering policy to be applied to the matched items. Default is FilterPolicy.Include.
- extract_matching_regex(*args, **kwargs)¶
Overloaded function.
extract_matching_regex(self: pybit7z._core.BitMemExtractor, in_archive: bytes, regex: str, out_dir: str = ‘’, policy: pybit7z._core.FilterPolicy = FilterPolicy.Include) -> None
Extracts the files in the archive that match the given regex pattern to the chosen directory.
- Parameters:
in_archive – the input archive to extract from.
regex – the regex pattern to be used for matching the files.
out_dir – the output directory where the extracted files will be placed.
policy – the filtering policy to be applied to the matched items. Default is FilterPolicy.Include.
extract_matching_regex(self: pybit7z._core.BitMemExtractor, in_archive: bytes, regex: str, policy: pybit7z._core.FilterPolicy = FilterPolicy.Include) -> bytes
Extracts to the output buffer the first file in the archive matching the given regex pattern.
- test(self: pybit7z._core.BitMemExtractor, in_archive: bytes) None¶
Tests the given archive without extracting its content.
If the archive is not valid, a BitException is thrown!
- Parameters:
in_archive – the input archive to be tested.
- class pybit7z.BitNestedArchiveReader¶
Bases:
BitAbstractArchiveOpenerThe BitNestedArchiveReader class allows reading and extracting nested archives (e.g. the tarball inside a .tar.gz archive).
- archive_property(self: pybit7z._core.BitNestedArchiveReader, arg0: pybit7z._core.BitProperty) pybit7z._core.BitPropVariant¶
Gets the specified archive property.
- Parameters:
property – the property to be retrieved.
- Returns:
the current value of the archive property or an empty BitPropVariant if no value is specified.
- detected_format(self: pybit7z._core.BitNestedArchiveReader) pybit7z._core.BitInFormat¶
the detected format of the nested archive.
- extract_to(self: pybit7z._core.BitNestedArchiveReader, out_dir: str) None¶
Extracts the archive to the chosen directory.
- Parameters:
out_dir – the output directory where the extracted files will be put.
- item_property(self: pybit7z._core.BitNestedArchiveReader, index: int, property: pybit7z._core.BitProperty) pybit7z._core.BitPropVariant¶
Gets the specified property of an item in the archive.
- Parameters:
index – the index of the item.
property – the property to be retrieved.
- Returns:
the current value of the item property or an empty BitPropVariant if the item has no value.
- items(self: pybit7z._core.BitNestedArchiveReader) list[pybit7z._core.BitArchiveItemInfo]¶
all the archive items as BitArchiveItemInfo objects.
- items_count(self: pybit7z._core.BitNestedArchiveReader) int¶
the number of items contained in the nested archive.
- max_memory_usage(self: pybit7z._core.BitNestedArchiveReader) int¶
the max memory usage limit applied while extracting the parent archive.
- open_count(self: pybit7z._core.BitNestedArchiveReader) int¶
the number of times the parent archive was extracted and the nested archive was opened.
- set_max_memory_usage(self: pybit7z._core.BitNestedArchiveReader, value: int) None¶
Sets the max memory usage limit to be used while extracting the parent archive.
- Parameters:
value – the max memory limit to be used (in bytes).
- test(self: pybit7z._core.BitNestedArchiveReader) None¶
Tests the archive without extracting its content.
- Raises:
BitException – if the archive is not valid.
- class pybit7z.BitOutputArchive¶
Bases:
pybind11_object- add_directory(self: pybit7z._core.BitOutputArchive, in_dir: str) None¶
Adds the given directory path and all its content.
- Parameters:
in_dir – the path of the directory to be added to the archive.
- add_directory_contents(*args, **kwargs)¶
Overloaded function.
add_directory_contents(self: pybit7z._core.BitOutputArchive, in_dir: str, filter: str, recursive: bool) -> None
Adds the contents of the given directory path.
This function iterates through the specified directory and adds its contents based on the provided wildcard filter. Optionally, the operation can be recursive, meaning it will include subdirectories and their contents.
- Parameters:
in_dir – the directory where to search for files to be added to the output archive.
filter – the wildcard filter to be used for searching the files.
recursive – recursively search the files in the given directory and all of its subdirectories.
add_directory_contents(self: pybit7z._core.BitOutputArchive, in_dir: str, filter: str = ‘*’, policy: pybit7z._core.FilterPolicy = FilterPolicy.Include, recursive: bool = True) -> None
Adds the contents of the given directory path.
This function iterates through the specified directory and adds its contents based on the provided wildcard filter and policy. Optionally, the operation can be recursive, meaning it will include subdirectories and their contents.
- Parameters:
in_dir – the directory where to search for files to be added to the output archive.
filter – the wildcard filter to be used for searching the files.
recursive – recursively search the files in the given directory and all of its subdirectories.
policy – the filtering policy to be applied to the matched items. Default is FilterPolicy.Include.
- add_file(*args, **kwargs)¶
Overloaded function.
add_file(self: object, input: bytes, name: str) -> pybit7z._core.BitInputItem
Adds the given memory buffer, with an optional user-defined path to be used in the output archive.
- Parameters:
input – the memory buffer to be added to the output archive.
name – user-defined path to be used inside the output archive.
- Returns:
A reference to the input item just added, valid until the next call that adds items to the archive.
add_file(self: pybit7z._core.BitOutputArchive, in_file: str, name: str = ‘’) -> pybit7z._core.BitInputItem
- Adds the given file path, with an optional user-defined path to be used in the
output archive.
- Args:
in_file: the path to the filesystem file to be added to the output archive. name: (optional) user-defined path to be used inside the output archive.
- Note:
If a directory path is given, a BitException is thrown.
- Returns:
A reference to the input item just added, valid until the next call that adds items to the archive.
- add_files(*args, **kwargs)¶
Overloaded function.
add_files(self: pybit7z._core.BitOutputArchive, in_files: list[str]) -> None
Adds all the files in the given vector of filesystem paths.
- Parameters:
in_files – the vector of paths to files.
Note
Paths to directories are ignored.
add_files(self: pybit7z._core.BitOutputArchive, in_dir: str, filter: str, recursive: bool) -> None
Adds all the files inside the given directory path that match the given wildcard filter.
- Parameters:
in_dir – the directory where to search for files to be added to the output archive.
filter – (optional) the filter pattern to be used to select the files to be added.
recursive – (optional) if true, the directory will be searched recursively.
Note
If a file path is given, a BitException is thrown.
add_files(self: pybit7z._core.BitOutputArchive, in_dir: str, filter: str = ‘*’, policy: pybit7z._core.FilterPolicy = FilterPolicy.Include, recursive: bool = True) -> None
Adds all the files inside the given directory path that match the given wildcard filter, with the specified filter policy.
- Parameters:
in_dir – the directory where to search for files to be added to the output archive.
filter – (optional) the wildcard filter to be used for searching the files.
recursive – (optional) recursively search the files in the given directory and all of its subdirectories.
policy – (optional) the filtering policy to be applied to the matched items. Default is FilterPolicy.Include.
- add_items(*args, **kwargs)¶
Overloaded function.
add_items(self: pybit7z._core.BitOutputArchive, paths: list[str]) -> None
Adds all the items that can be found by indexing the given vector of filesystem paths.
- Parameters:
paths – the paths to be added to the archive.
add_items(self: pybit7z._core.BitOutputArchive, files: dict[str, str]) -> None
Adds all the items that can be found by indexing the keys of the given map of filesystem paths; the corresponding mapped values are the user-defined paths wanted inside the output archive.
- Parameters:
files – the map of file paths and their contents to be added to the archive.
- compress_to(*args, **kwargs)¶
Overloaded function.
compress_to(self: pybit7z._core.BitOutputArchive, out_file: str) -> None
Compresses all the items added to this object to the specified archive file path.
- Parameters:
out_file – the output archive file path.
Note
If this object was created by passing an input archive file path, and this latter is the same as the out_file path parameter, the file will be updated.
compress_to(self: pybit7z._core.BitOutputArchive) -> bytes
Compresses all the items added to this object to the specified buffer.
- items_count(self: pybit7z._core.BitOutputArchive) int¶
the number of items in the archive.
- class pybit7z.BitPropVariant¶
Bases:
pybind11_objectThe BitPropVariant struct is a light extension to the WinAPI PROPVARIANT struct providing useful getters.
- clear(self: pybit7z._core.BitPropVariant) None¶
Clears the variant.
- get_bool(self: pybit7z._core.BitPropVariant) bool¶
- get_file_time(self: pybit7z._core.BitPropVariant) datetime.datetime¶
- get_int64(self: pybit7z._core.BitPropVariant) int¶
- get_native_string(self: pybit7z._core.BitPropVariant) str¶
- get_string(self: pybit7z._core.BitPropVariant) str¶
- get_uint64(self: pybit7z._core.BitPropVariant) int¶
- is_bool(self: pybit7z._core.BitPropVariant) bool¶
- is_file_time(self: pybit7z._core.BitPropVariant) bool¶
- is_int16(self: pybit7z._core.BitPropVariant) bool¶
- is_int32(self: pybit7z._core.BitPropVariant) bool¶
- is_int64(self: pybit7z._core.BitPropVariant) bool¶
- is_int8(self: pybit7z._core.BitPropVariant) bool¶
- is_string(self: pybit7z._core.BitPropVariant) bool¶
- is_uint16(self: pybit7z._core.BitPropVariant) bool¶
- is_uint32(self: pybit7z._core.BitPropVariant) bool¶
- is_uint64(self: pybit7z._core.BitPropVariant) bool¶
- is_uint8(self: pybit7z._core.BitPropVariant) bool¶
- type(self: pybit7z._core.BitPropVariant) pybit7z._core.BitPropVariantType¶
Returns the type of the variant.
- class pybit7z.BitPropVariantType¶
Bases:
pybind11_objectThe BitPropVariantType enum represents the possible types that a BitPropVariant can store.
Members:
Empty
Bool
String
UInt8
UInt16
UInt32
UInt64
Int8
Int16
Int32
Int64
FileTime
- Bool = <BitPropVariantType.Bool: 1>¶
- Empty = <BitPropVariantType.Empty: 0>¶
- FileTime = <BitPropVariantType.FileTime: 11>¶
- Int16 = <BitPropVariantType.Int16: 8>¶
- Int32 = <BitPropVariantType.Int32: 9>¶
- Int64 = <BitPropVariantType.Int64: 10>¶
- Int8 = <BitPropVariantType.Int8: 7>¶
- String = <BitPropVariantType.String: 2>¶
- UInt16 = <BitPropVariantType.UInt16: 4>¶
- UInt32 = <BitPropVariantType.UInt32: 5>¶
- UInt64 = <BitPropVariantType.UInt64: 6>¶
- UInt8 = <BitPropVariantType.UInt8: 3>¶
- BitPropVariantType.name -> str
- property value¶
- class pybit7z.BitProperty¶
Bases:
pybind11_objectThe BitProperty enum represents the archive/item properties that 7-zip can read or write.
Members:
NoProperty
MainSubfile
HandlerItemIndex
Path
Name
Extension
IsDir
Size
PackSize
Attrib
CTime
ATime
MTime
Solid
Commented
Encrypted
SplitBefore
SplitAfter
DictionarySize
CRC
Type
IsAnti
Method
HostOS
FileSystem
User
Group
Block
Comment
Position
Prefix
NumSubDirs
NumSubFiles
UnpackVer
Volume
IsVolume
Offset
Links
NumBlocks
NumVolumes
TimeType
Bit64
BigEndian
Cpu
PhySize
HeadersSize
Checksum
Characters
Va
Id
ShortName
CreatorApp
SectorSize
PosixAttrib
SymLink
Error
TotalSize
FreeSpace
ClusterSize
VolumeName
LocalName
Provider
NtSecure
IsAltStream
IsAux
IsDeleted
IsTree
Sha1
Sha256
ErrorType
NumErrors
ErrorFlags
WarningFlags
Warning
NumStreams
NumAltStreams
AltStreamsSize
VirtualSize
UnpackSize
TotalPhySize
VolumeIndex
SubType
ShortComment
CodePage
IsNotArcType
PhySizeCantBeDetected
ZerosTailIsAllowed
TailSize
EmbeddedStubSize
NtReparse
HardLink
INode
StreamId
ReadOnly
OutName
CopyLink
- ATime = <BitProperty.ATime: 11>¶
- AltStreamsSize = <BitProperty.AltStreamsSize: 76>¶
- Attrib = <BitProperty.Attrib: 9>¶
- BigEndian = <BitProperty.BigEndian: 42>¶
- Bit64 = <BitProperty.Bit64: 41>¶
- Block = <BitProperty.Block: 27>¶
- CRC = <BitProperty.CRC: 19>¶
- CTime = <BitProperty.CTime: 10>¶
- Characters = <BitProperty.Characters: 47>¶
- Checksum = <BitProperty.Checksum: 46>¶
- ClusterSize = <BitProperty.ClusterSize: 58>¶
- CodePage = <BitProperty.CodePage: 83>¶
- Comment = <BitProperty.Comment: 28>¶
- Commented = <BitProperty.Commented: 14>¶
- CopyLink = <BitProperty.CopyLink: 95>¶
- Cpu = <BitProperty.Cpu: 43>¶
- CreatorApp = <BitProperty.CreatorApp: 51>¶
- DictionarySize = <BitProperty.DictionarySize: 18>¶
- EmbeddedStubSize = <BitProperty.EmbeddedStubSize: 88>¶
- Encrypted = <BitProperty.Encrypted: 15>¶
- Error = <BitProperty.Error: 55>¶
- ErrorFlags = <BitProperty.ErrorFlags: 71>¶
- ErrorType = <BitProperty.ErrorType: 69>¶
- Extension = <BitProperty.Extension: 5>¶
- FileSystem = <BitProperty.FileSystem: 24>¶
- FreeSpace = <BitProperty.FreeSpace: 57>¶
- Group = <BitProperty.Group: 26>¶
- HandlerItemIndex = <BitProperty.HandlerItemIndex: 2>¶
- HardLink = <BitProperty.HardLink: 90>¶
- HeadersSize = <BitProperty.HeadersSize: 45>¶
- HostOS = <BitProperty.HostOS: 23>¶
- INode = <BitProperty.INode: 91>¶
- Id = <BitProperty.Id: 49>¶
- IsAltStream = <BitProperty.IsAltStream: 63>¶
- IsAnti = <BitProperty.IsAnti: 21>¶
- IsAux = <BitProperty.IsAux: 64>¶
- IsDeleted = <BitProperty.IsDeleted: 65>¶
- IsDir = <BitProperty.IsDir: 6>¶
- IsNotArcType = <BitProperty.IsNotArcType: 84>¶
- IsTree = <BitProperty.IsTree: 66>¶
- IsVolume = <BitProperty.IsVolume: 35>¶
- Links = <BitProperty.Links: 37>¶
- LocalName = <BitProperty.LocalName: 60>¶
- MTime = <BitProperty.MTime: 12>¶
- MainSubfile = <BitProperty.MainSubfile: 1>¶
- Method = <BitProperty.Method: 22>¶
- Name = <BitProperty.Name: 4>¶
- NoProperty = <BitProperty.NoProperty: 0>¶
- NtReparse = <BitProperty.NtReparse: 89>¶
- NtSecure = <BitProperty.NtSecure: 62>¶
- NumAltStreams = <BitProperty.NumAltStreams: 75>¶
- NumBlocks = <BitProperty.NumBlocks: 38>¶
- NumErrors = <BitProperty.NumErrors: 70>¶
- NumStreams = <BitProperty.NumStreams: 74>¶
- NumSubDirs = <BitProperty.NumSubDirs: 31>¶
- NumSubFiles = <BitProperty.NumSubFiles: 32>¶
- NumVolumes = <BitProperty.NumVolumes: 39>¶
- Offset = <BitProperty.Offset: 36>¶
- OutName = <BitProperty.OutName: 94>¶
- PackSize = <BitProperty.PackSize: 8>¶
- Path = <BitProperty.Path: 3>¶
- PhySize = <BitProperty.PhySize: 44>¶
- PhySizeCantBeDetected = <BitProperty.PhySizeCantBeDetected: 85>¶
- Position = <BitProperty.Position: 29>¶
- PosixAttrib = <BitProperty.PosixAttrib: 53>¶
- Prefix = <BitProperty.Prefix: 30>¶
- Provider = <BitProperty.Provider: 61>¶
- ReadOnly = <BitProperty.ReadOnly: 93>¶
- SectorSize = <BitProperty.SectorSize: 52>¶
- Sha1 = <BitProperty.Sha1: 67>¶
- Sha256 = <BitProperty.Sha256: 68>¶
- ShortComment = <BitProperty.ShortComment: 82>¶
- ShortName = <BitProperty.ShortName: 50>¶
- Size = <BitProperty.Size: 7>¶
- Solid = <BitProperty.Solid: 13>¶
- SplitAfter = <BitProperty.SplitAfter: 17>¶
- SplitBefore = <BitProperty.SplitBefore: 16>¶
- StreamId = <BitProperty.StreamId: 92>¶
- SubType = <BitProperty.SubType: 81>¶
- SymLink = <BitProperty.SymLink: 54>¶
- TailSize = <BitProperty.TailSize: 87>¶
- TimeType = <BitProperty.TimeType: 40>¶
- TotalPhySize = <BitProperty.TotalPhySize: 79>¶
- TotalSize = <BitProperty.TotalSize: 56>¶
- Type = <BitProperty.Type: 20>¶
- UnpackSize = <BitProperty.UnpackSize: 78>¶
- UnpackVer = <BitProperty.UnpackVer: 33>¶
- User = <BitProperty.User: 25>¶
- Va = <BitProperty.Va: 48>¶
- VirtualSize = <BitProperty.VirtualSize: 77>¶
- Volume = <BitProperty.Volume: 34>¶
- VolumeIndex = <BitProperty.VolumeIndex: 80>¶
- VolumeName = <BitProperty.VolumeName: 59>¶
- Warning = <BitProperty.Warning: 73>¶
- WarningFlags = <BitProperty.WarningFlags: 72>¶
- ZerosTailIsAllowed = <BitProperty.ZerosTailIsAllowed: 86>¶
- BitProperty.name -> str
- property value¶
- class pybit7z.BitStringCompressor¶
Bases:
BitAbstractArchiveCreator- compress_file(*args, **kwargs)¶
Overloaded function.
compress_file(self: pybit7z._core.BitStringCompressor, in_file: str, out_file: str, input_name: str = ‘’) -> None
Compresses the given file to the chosen archive.
- Parameters:
in_file – the input file to be compressed.
out_file – the path (relative or absolute) to the output archive file.
input_name – the name of the input file in the archive (optional).
compress_file(self: pybit7z._core.BitStringCompressor, in_file: str, input_name: str = ‘’) -> bytes
Compresses the given file to a memory buffer.
- Parameters:
in_file – the input file to be compressed.
input_name – the name of the input file in the archive (optional).
- class pybit7z.BitStringExtractor¶
Bases:
BitAbstractArchiveOpener- extract(*args, **kwargs)¶
Overloaded function.
extract(self: pybit7z._core.BitStringExtractor, in_archive: str, out_dir: str) -> None
Extracts the given archive to the chosen directory.
extract(self: pybit7z._core.BitStringExtractor, in_archive: str, index: int) -> bytes
Extracts the specified item from the given archive to a memory buffer.
extract(self: pybit7z._core.BitStringExtractor, in_archive: str) -> dict[str, bytes]
Extracts all the items from the given archive to a dictionary of memory buffers.
- extract_items(self: pybit7z._core.BitStringExtractor, in_archive: str, indices: list[int], out_dir: str = '') None¶
Extracts the specified items from the given archive to the chosen directory.
- Parameters:
in_archive – the input archive to extract from.
indices – the indices of the files in the archive that should be extracted.
out_dir – the output directory where the extracted files will be placed.
- extract_matching(*args, **kwargs)¶
Overloaded function.
extract_matching(self: pybit7z._core.BitStringExtractor, in_archive: str, pattern: str, out_dir: str = ‘’, policy: pybit7z._core.FilterPolicy = FilterPolicy.Include) -> None
Extracts the files in the archive that match the given wildcard pattern to the chosen directory. :param in_archive: the input archive to be extracted. :param pattern: the wildcard pattern to be used for matching the files. :param out_dir: the directory where to extract the matching files. :param policy: the filtering policy to be applied to the matched items. Default is FilterPolicy.Include.
extract_matching(self: pybit7z._core.BitStringExtractor, in_archive: str, pattern: str, policy: pybit7z._core.FilterPolicy = FilterPolicy.Include) -> bytes
Extracts to the output buffer the first file in the archive matching the given wildcard pattern.
- Parameters:
in_archive – the input archive to extract from.
pattern – the wildcard pattern to be used for matching the files.
policy – the filtering policy to be applied to the matched items. Default is FilterPolicy.Include.
- extract_matching_regex(*args, **kwargs)¶
Overloaded function.
extract_matching_regex(self: pybit7z._core.BitStringExtractor, in_archive: str, regex: str, out_dir: str, policy: pybit7z._core.FilterPolicy = FilterPolicy.Include) -> None
Extracts the files in the archive that match the given regex pattern to the chosen directory.
- Parameters:
in_archive – the input archive to extract from.
regex – the regex pattern to be used for matching the files.
out_dir – the output directory where the extracted files will be placed.
policy – the filtering policy to be applied to the matched items. Default is FilterPolicy.Include.
extract_matching_regex(self: pybit7z._core.BitStringExtractor, in_archive: str, regex: str, policy: pybit7z._core.FilterPolicy = FilterPolicy.Include) -> bytes
Extracts to the output buffer the first file in the archive matching the given regex pattern.
- Parameters:
in_archive – the input archive to extract from.
regex – the regex pattern to be used for matching the files.
policy – the filtering policy to be applied to the matched items. Default is FilterPolicy.Include.
- class pybit7z.DeletePolicy¶
Bases:
pybind11_objectDelete policy for archive items.
Members:
ItemOnly
RecurseDirs
- ItemOnly = <DeletePolicy.ItemOnly: 0>¶
- RecurseDirs = <DeletePolicy.RecurseDirs: 1>¶
- DeletePolicy.name -> str
- property value¶
- class pybit7z.EncryptionScope¶
Bases:
pybind11_objectMembers:
DataOnly : Only the archive’s file data is encrypted.
DataAndHeaders : Both the archive’s file data and headers are encrypted (valid only for the 7z format).
- DataAndHeaders = <EncryptionScope.DataAndHeaders: 1>¶
- DataOnly = <EncryptionScope.DataOnly: 0>¶
- EncryptionScope.name -> str
- property value¶
- class pybit7z.FilterPolicy¶
Bases:
pybind11_objectMembers:
Include : Extract/compress the items that match the pattern.
Exclude : Do not extract/compress the items that match the pattern.
- Exclude = <FilterPolicy.Exclude: 1>¶
- Include = <FilterPolicy.Include: 0>¶
- FilterPolicy.name -> str
- property value¶
- class pybit7z.FormatFeatures¶
Bases:
pybind11_objectFeatures of a format supported by bit7z
Members:
MultipleFiles : Archive supports multiple files.
SolidArchive : Archive supports solid mode.
CompressionLevel : Archive supports compression level.
Encryption : Archive supports encryption.
HeaderEncryption : Archive supports encrypted headers.
MultipleMethods : Archive supports multiple compression methods.
- CompressionLevel = <FormatFeatures.CompressionLevel: 4>¶
- Encryption = <FormatFeatures.Encryption: 8>¶
- HeaderEncryption = <FormatFeatures.HeaderEncryption: 16>¶
- MultipleFiles = <FormatFeatures.MultipleFiles: 1>¶
- MultipleMethods = <FormatFeatures.MultipleMethods: 32>¶
- SolidArchive = <FormatFeatures.SolidArchive: 2>¶
- FormatFeatures.name -> str
- property value¶
- class pybit7z.OverwriteMode¶
Bases:
pybind11_objectEnumeration representing how a handler should deal when an output file already exists.
Members:
Nothing : The handler will throw an exception if the output file or buffer already exists.
Overwrite : The handler will overwrite the old file or buffer with the new one.
Skip : The handler will skip writing to the output file or buffer.
- Nothing = <OverwriteMode.Nothing: 0>¶
- Overwrite = <OverwriteMode.Overwrite: 1>¶
- Skip = <OverwriteMode.Skip: 2>¶
- OverwriteMode.name -> str
- property value¶
- class pybit7z.SymlinkPolicy¶
Bases:
pybind11_objectThe SymlinkPolicy enum specifies how symbolic links should be handled when adding files to an archive.
Members:
Follow : Follow symbolic links, storing the content of the pointed-to file.
DoNotFollow : Do not follow symbolic links, storing the link itself.
- DoNotFollow = <SymlinkPolicy.DoNotFollow: 1>¶
- Follow = <SymlinkPolicy.Follow: 0>¶
- SymlinkPolicy.name -> str
- property value¶
- class pybit7z.UpdateMode¶
Bases:
pybind11_objectMembers:
Nothing
Append
Update
- Append = <UpdateMode.Append: 1>¶
- Nothing = <UpdateMode.Nothing: 0>¶
- Update = <UpdateMode.Update: 2>¶
- UpdateMode.name -> str
- property value¶
- pybit7z.default_lib7zip()[source]¶
Get the default lib7zip library path under the package directory.
- Return type:
- Returns:
The default lib7zip library path.
- pybit7z.default_plugin_dir()[source]¶
Get the default directory containing the external Codecs/ and Formats/ plugin subdirectories under the package directory.
- Return type:
- Returns:
The default plugin directory path.
- pybit7z.lib7zip_context(path='', large_page_mode=True)[source]¶
A context manager to create a Bit7zLibrary instance.
- Parameters:
- Yields:
Bit7zLibrary– A Bit7zLibrary instance.- Raises:
FileNotFoundError – If the lib7zip library is not found.
- pybit7z.loader_context()[source]¶
A context manager that creates a
Bit7zLibraryLoader, yields it to the caller for explicitload()/try_load(), and automatically unloads on exit if the loader is still loaded.The caller has full control over when and how to load the library:
with pybit7z.loader_context() as loader: if loader.try_load(pybit7z.default_lib7zip()): lib = loader.library() ... else: print("lib7zip unavailable") # loader.unload() called automatically if loaded
- Yields:
Bit7zLibraryLoader– A fresh, unloaded Bit7zLibraryLoader instance.