-
-
Notifications
You must be signed in to change notification settings - Fork 147
BitArchiveWriter
The BitArchiveWriter class allows creating new archives or updating old ones with new items.
#include <bit7z/bitarchivewriter.hpp>inherits from BitAbstractArchiveCreator, BitOutputArchive.
| Return type | Name |
|---|---|
| BitArchiveWriter( const Bit7zLibrary& lib, buffer_t&& inArchive, ArchiveStartOffset startOffset, const BitInOutFormat& format, const tstring& password = {} ) = delete | |
| BitArchiveWriter( const Bit7zLibrary& lib, buffer_t&& inArchive, const BitInOutFormat& format, const tstring& password = {} ) = delete | |
| BitArchiveWriter( const Bit7zLibrary& lib, const BitInOutFormat& format ) | |
| BitArchiveWriter( const Bit7zLibrary& lib, const buffer_t& inArchive, ArchiveStartOffset startOffset, const BitInOutFormat& format, const tstring& password = {} ) | |
| BitArchiveWriter( const Bit7zLibrary& lib, const buffer_t& inArchive, const BitInOutFormat& format, const tstring& password = {} ) | |
| BitArchiveWriter( const Bit7zLibrary& lib, const tstring& inArchive, ArchiveStartOffset startOffset, const BitInOutFormat& format, const tstring& password = {} ) | |
| BitArchiveWriter( const Bit7zLibrary& lib, const tstring& inArchive, const BitInOutFormat& format, const tstring& password = {} ) | |
| BitArchiveWriter( const Bit7zLibrary& lib, std::istream& inArchive, ArchiveStartOffset startOffset, const BitInOutFormat& format, const tstring& password = {} ) | |
| BitArchiveWriter( const Bit7zLibrary& lib, std::istream& inArchive, const BitInOutFormat& format, const tstring& password = {} ) | |
| void | addDirectory( const tstring& inDir ) |
| void | addDirectoryContents( const tstring& inDir, const tstring& filter, bool recursive ) |
| void | addDirectoryContents( const tstring& inDir, const tstring& filter = "*", FilterPolicy policy = FilterPolicy::Include, bool recursive = true ) |
| BitInputItem & | addFile( buffer_t&& inBuffer, const tstring& name ) = delete |
| BitInputItem & | addFile( const buffer_t& inBuffer, const tstring& name ) |
| BitInputItem & | addFile( const tstring& inFile, const tstring& name = {} ) |
| BitInputItem & | addFile( std::istream& inStream, const tstring& name ) |
| void | addFiles( const std::vector< tstring >& inFiles ) |
| void | addFiles( const tstring& inDir, const tstring& filter, bool recursive ) |
| void | addFiles( const tstring& inDir, const tstring& filter = "*", FilterPolicy policy = FilterPolicy::Include, bool recursive = true ) |
| void | addItems( const std::map< tstring, tstring >& inPaths ) |
| void | addItems( const std::vector< std::pair< tstring, tstring > >& inPaths ) |
| void | addItems( const std::vector< tstring >& inPaths ) |
| void | clearPassword() noexcept |
| const BitInOutFormat & | compressionFormat() const noexcept |
| BitCompressionLevel | compressionLevel() const noexcept |
| BitCompressionMethod | compressionMethod() const noexcept |
| void | compressTo( buffer_t& outBuffer ) |
| void | compressTo( const tstring& outFile ) |
| void | compressTo( std::ostream& outStream ) |
| const BitAbstractArchiveCreator & | creator() const noexcept |
| bool | cryptHeaders() const noexcept |
| std::uint32_t | dictionarySize() const noexcept |
| const FileCallback & | fileCallback() const |
| const BitInFormat &override | format() const noexcept |
| const BitAbstractArchiveHandler & | handler() const noexcept |
| bool | isPasswordDefined() const noexcept |
| std::uint32_t | itemsCount() const |
| const Bit7zLibrary & | library() const noexcept |
| OverwriteMode | overwriteMode() const noexcept |
| const tstring & | password() const |
| const PasswordCallback & | passwordCallback() const |
| const ProgressCallback & | progressCallback() const |
| const RatioCallback & | ratioCallback() const |
| bool | retainDirectories() const noexcept |
| void | setCompressionLevel( BitCompressionLevel level ) noexcept |
| void | setCompressionMethod( BitCompressionMethod method ) |
| void | setDictionarySize( std::uint32_t dictionarySize ) |
| void | setFileCallback( const FileCallback& callback ) |
| void | setFormatProperty( const wchar_t( &name )[N], const T& value ) noexcept |
| void | setFormatProperty( const wchar_t( &name )[N], T value ) noexcept |
| void | setOverwriteMode( OverwriteMode mode ) |
| void | setPassword( const tstring& password ) override |
| void | setPassword( const tstring& password, bool cryptHeaders ) |
| void | setPassword( const tstring& password, EncryptionScope scope ) |
| void | setPasswordCallback( const PasswordCallback& callback ) |
| void | setProgressCallback( const ProgressCallback& callback ) |
| void | setRatioCallback( const RatioCallback& callback ) |
| void | setRetainDirectories( bool retain ) noexcept |
| void | setSolidMode( bool solidMode ) noexcept |
| void | setStoreCreationTime( bool storeCreationTime ) noexcept |
| void | setStoreLastAccessTime( bool storeLastAccessTime ) noexcept |
| void | setStoreLastWriteTime( bool storeLastWriteTime ) noexcept |
| void | setStoreOpenFiles( bool storeOpenFiles ) noexcept |
| void | setStoreSymbolicLinks( bool storeSymlinks ) noexcept |
| void | setThreadsCount( std::uint32_t threadsCount ) noexcept |
| void | setTotalCallback( const TotalCallback& callback ) |
| void | setUpdateMode( bool canUpdate ) |
| void | setUpdateMode( UpdateMode mode ) |
| void | setVolumeSize( std::uint64_t volumeSize ) noexcept |
| void | setWordSize( std::uint32_t wordSize ) |
| bool | solidMode() const noexcept |
| bool | storeCreationTime() const noexcept |
| bool | storeLastAccessTime() const noexcept |
| bool | storeLastWriteTime() const noexcept |
| bool | storeOpenFiles() const noexcept |
| bool | storeSymbolicLinks() const noexcept |
| std::uint32_t | threadsCount() const noexcept |
| const TotalCallback & | totalCallback() const |
| UpdateMode | updateMode() const noexcept |
| std::uint64_t | volumeSize() const noexcept |
| std::uint32_t | wordSize() const noexcept |
BitArchiveWriter( const Bit7zLibrary& lib, buffer_t&& inArchive, ArchiveStartOffset startOffset, const BitInOutFormat& format, const tstring& password = {} ) = delete
Deleted overload preventing the use of a temporary input buffer. The input archive's bytes are read lazily while compressing (to copy retained items), so the buffer must outlive the BitArchiveWriter; a temporary would dangle.
BitArchiveWriter( const Bit7zLibrary& lib, buffer_t&& inArchive, const BitInOutFormat& format, const tstring& password = {} ) = delete
Deleted overload preventing the use of a temporary input buffer. The input archive's bytes are read lazily while compressing (to copy retained items), so the buffer must outlive the BitArchiveWriter; a temporary would dangle.
BitArchiveWriter( const Bit7zLibrary& lib, const BitInOutFormat& format )
Constructs an empty BitArchiveWriter object that can write archives of the specified format.
Parameters:
- lib: the 7z library to use.
- format: the output archive format.
BitArchiveWriter( const Bit7zLibrary& lib, const buffer_t& inArchive, ArchiveStartOffset startOffset, const BitInOutFormat& format, const tstring& password = {} )
Constructs a BitArchiveWriter object, reading the archive in the given buffer.
Parameters:
- lib: the 7z library to use.
- inArchive: the buffer containing the input archive.
- startOffset: whether to search for the archive's start throughout the entire file or only at the beginning.
- format: the input/output archive format.
- password: (optional) the password needed to read the input archive.
BitArchiveWriter( const Bit7zLibrary& lib, const buffer_t& inArchive, const BitInOutFormat& format, const tstring& password = {} )
Constructs a BitArchiveWriter object, reading the archive in the given buffer.
Parameters:
- lib: the 7z library to use.
- inArchive: the buffer containing the input archive.
- format: the input/output archive format.
- password: (optional) the password needed to read the input archive.
BitArchiveWriter( const Bit7zLibrary& lib, const tstring& inArchive, ArchiveStartOffset startOffset, const BitInOutFormat& format, const tstring& password = {} )
Constructs a BitArchiveWriter object, reading the given archive file path.
Parameters:
- lib: the 7z library to use.
- inArchive: the path to an input archive file.
- startOffset: whether to search for the archive's start throughout the entire file or only at the beginning.
- format: the input/output archive format.
- password: (optional) the password needed to read the input archive.
BitArchiveWriter( const Bit7zLibrary& lib, const tstring& inArchive, const BitInOutFormat& format, const tstring& password = {} )
Constructs a BitArchiveWriter object, reading the given archive file path.
Parameters:
- lib: the 7z library to use.
- inArchive: the path to an input archive file.
- format: the input/output archive format.
- password: (optional) the password needed to read the input archive.
BitArchiveWriter( const Bit7zLibrary& lib, std::istream& inArchive, ArchiveStartOffset startOffset, const BitInOutFormat& format, const tstring& password = {} )
Constructs a BitArchiveWriter object, reading the archive from the given standard input stream.
Parameters:
- lib: the 7z library to use.
- inArchive: the standard stream of the input archive.
- startOffset: whether to search for the archive's start throughout the entire file or only at the beginning.
- format: the input/output archive format.
- password: (optional) the password needed to read the input archive.
BitArchiveWriter( const Bit7zLibrary& lib, std::istream& inArchive, const BitInOutFormat& format, const tstring& password = {} )
Constructs a BitArchiveWriter object, reading the archive from the given standard input stream.
Parameters:
- lib: the 7z library to use.
- inArchive: the standard stream of the input archive.
- format: the input/output archive format.
- password: (optional) the password needed to read the input archive.
void addDirectory( const tstring& inDir )
Adds the given directory path and all its content.
Parameters:
- inDir: the path of the directory to be added to the archive.
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:
- inDir: 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.
void addDirectoryContents( const tstring& inDir, const tstring& filter = "*", FilterPolicy policy = FilterPolicy::Include, bool recursive = true )
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:
- inDir: 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.
BitInputItem & addFile( buffer_t&& inBuffer, const tstring& name ) = delete
Deleted overload preventing the addition of a temporary buffer. The added item only keeps a reference to the buffer, which is read later when compressing; a temporary would dangle, so passing one is rejected at compile time.
BitInputItem & addFile( const buffer_t& inBuffer, const tstring& name )
Adds the given buffer file, using the given name as a path when compressed in the output archive.
Parameters:
- inBuffer: the buffer containing the file 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.
BitInputItem & addFile( const tstring& inFile, const tstring& name = {} )
Adds the given file path, with an optional user-defined path to be used in the output archive.
Note
If a directory path is given, a BitException is thrown.
Parameters:
- inFile: 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.
Returns a reference to the input item just added, valid until the next call that adds items to the archive.
BitInputItem & addFile( std::istream& inStream, const tstring& name )
Adds the given standard input stream, using the given name as a path when compressed in the output archive.
Parameters:
- inStream: the input stream to be added.
- name: the name of the file inside the output archive.
Returns a reference to the input item just added, valid until the next call that adds items to the archive.
void addFiles( const std::vector< tstring >& inFiles )
Adds all the files in the given vector of filesystem paths.
Note
Paths to directories are ignored.
Parameters:
- inFiles: the vector of paths to files.
Adds all the files inside the given directory path that match the given wildcard filter.
Parameters:
- inDir: 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.
void addFiles( const tstring& inDir, const tstring& filter = "*", FilterPolicy policy = FilterPolicy::Include, bool recursive = true )
Adds all the files inside the given directory path that match the given wildcard filter.
Parameters:
- inDir: 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.
Adds all the items that can be found by indexing the keys of the given filesystem paths map; the corresponding mapped values are the user-defined paths wanted inside the output archive.
Parameters:
- inPaths: map of filesystem paths with the corresponding user-defined path desired inside the output archive.
void addItems( const std::vector< std::pair< tstring, tstring > >& inPaths )
Adds all the items that can be found by indexing the keys of the given filesystem paths map; the corresponding mapped values are the user-defined paths wanted inside the output archive.
Parameters:
- inPaths: map of filesystem paths with the corresponding user-defined path desired inside the output archive.
void addItems( const std::vector< tstring >& inPaths )
Adds all the items that can be found by indexing the given vector of filesystem paths.
Parameters:
- inPaths: the vector of filesystem paths.
Clear the current password used by the handler. Calling clearPassword() will disable the encryption/decryption of archives.
Note
This is equivalent to calling setPassword(L"").
const BitInOutFormat & compressionFormat() const noexcept
Returns the format used for creating/updating an archive.
BitCompressionLevel compressionLevel() const noexcept
Returns the compression level used for creating/updating an archive.
BitCompressionMethod compressionMethod() const noexcept
Returns the compression method used for creating/updating an archive.
Compresses all the items added to this object to the specified buffer.
Parameters:
- outBuffer: the output buffer.
void compressTo( const tstring& outFile )
Compresses all the items added to this object to the specified archive file path.
Note
If this object was created by passing an input archive file path, and this latter is the same as the outFile path parameter, the file will be updated.
Parameters:
- outFile: the output archive file path.
void compressTo( std::ostream& outStream )
Compresses all the items added to this object to the specified buffer.
Parameters:
- outStream: the output standard stream.
const BitAbstractArchiveCreator & creator() const noexcept
Returns a constant reference to the BitAbstractArchiveHandler object containing the settings for writing the output archive.
Returns whether the creator crypts also the headers of archives or not.
std::uint32_t dictionarySize() const noexcept
Returns the dictionary size used for creating/updating an archive.
const FileCallback & fileCallback() const
Returns the current file callback.
[virtual] const BitInFormat &override format() const noexcept
Returns the format used for creating/updating an archive.
const BitAbstractArchiveHandler & handler() const noexcept
Returns a constant reference to the BitAbstractArchiveHandler object containing the settings for writing the output archive.
Returns a boolean value indicating whether a password is defined or not.
std::uint32_t itemsCount() const
Returns the total number of items added to the output archive object.
const Bit7zLibrary & library() const noexcept
Returns the Bit7zLibrary object used by the handler.
OverwriteMode overwriteMode() const noexcept
Returns the current OverwriteMode.
const tstring & password() const
Returns the password used to open, extract, or encrypt the archive.
const PasswordCallback & passwordCallback() const
Returns the current password callback.
const ProgressCallback & progressCallback() const
Returns the current progress callback.
const RatioCallback & ratioCallback() const
Returns the current ratio callback.
Returns a boolean value indicating whether the directory structure must be preserved while extracting or compressing the archive.
void setCompressionLevel( BitCompressionLevel level ) noexcept
Sets the compression level to be used when creating/updating an archive.
Parameters:
- level: the compression level desired.
void setCompressionMethod( BitCompressionMethod method )
Sets the compression method to be used when creating/updating an archive.
Parameters:
- method: the compression method desired.
void setDictionarySize( std::uint32_t dictionarySize )
Sets the dictionary size to be used when creating/updating an archive.
Parameters:
- dictionarySize: the dictionary size desired.
void setFileCallback( const FileCallback& callback )
Sets the function to be called when the current file being processed changes.
Parameters:
- callback: the file callback to be used.
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 string name of the property to be set.
- value: The value to be used for the property.
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).
Parameters:
- name: The string name of the property to be set.
- value: The value to be used for the property.
void setOverwriteMode( OverwriteMode mode )
Sets how the handler should behave when it tries to output to an existing file or buffer.
Parameters:
- mode: the OverwriteMode to be used by the handler.
[virtual] void setPassword( const tstring& password ) override
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 setPassword(tstring, bool) method.
Note
Calling setPassword 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).
Note
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 setPassword(L"").
Parameters:
- password: the password to be used when creating/updating archives.
void setPassword( const tstring& password, bool cryptHeaders )
Warning
Deprecated: Since v4.1. Please use the overloaded function that takes an EncryptionScope enumerator.
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.
Note
Calling setPassword 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).
Note
Calling setPassword with "cryptHeaders" set to true does not have effects on formats different from 7z.
Note
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 setPassword(L"").
Parameters:
- password: the password to be used when creating/updating archives.
- cryptHeaders: if true, the headers of the output archives will be encrypted (valid only when using the 7z format).
void setPassword( const tstring& password, EncryptionScope scope )
Sets up a password for the output archive, specifying the encryption scope. 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 scope is EncryptionScope::DataAndHeaders, the archive headers will also be encrypted, resulting in a password request every time the output file will be opened.
Note
Calling setPassword 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).
Note
Using EncryptionScope::DataAndHeaders does not have effects on formats other than 7z.
Note
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 setPassword(L"").
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).
void setPasswordCallback( const PasswordCallback& callback )
Sets the function to be called when a password is needed to complete the ongoing operation.
Parameters:
- callback: the password callback to be used.
void setProgressCallback( const ProgressCallback& callback )
Sets the function to be called when the processed size of the ongoing operation is updated.
Note
The completion percentage of the current operation can be obtained by calculating static_cast<int>((100.0 * processed_size) / total_size).
Parameters:
- callback: the progress callback to be used.
void setRatioCallback( const RatioCallback& callback )
Sets the function to be called when the input processed size and current output size of the ongoing operation are known.
Note
The ratio percentage of a compression operation can be obtained by calculating static_cast<int>((100.0 * output_size) / input_size).
Parameters:
- callback: the ratio callback to be used.
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
Sets whether to use solid compression or not.
Note
Setting the solid compression mode to true has effect only when using the 7z format with multiple input files.
Parameters:
- solidMode: if true, it will be used the "solid compression" method.
Sets whether the creator will store creation timestamps of items.
Parameters:
- storeCreationTime: if true, creation timestamps of items will be stored in the output archive.
Sets whether the creator will store last access timestamps of items.
Parameters:
- storeLastAccessTime: if true, last access timestamps of items will be stored in the output archive.
Sets whether the creator will store last write timestamps of items.
Note
By default, all archive formats store last write timestamps; pass false to suppress them.
Parameters:
- storeLastWriteTime: if false, last write timestamps will be omitted from the output archive.
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.
Note
On non-Windows platforms this setting has no effect.
Parameters:
- storeOpenFiles: if true, the creator will attempt to compress files open by other processes.
Sets whether the creator will store symbolic links as links in the output archive.
Parameters:
- storeSymlinks: if true, symbolic links will be stored as links.
void setThreadsCount( std::uint32_t threadsCount ) noexcept
Sets the number of threads to be used when creating/updating an archive.
Parameters:
- threadsCount: the number of threads desired.
void setTotalCallback( const TotalCallback& callback )
Sets the function to be called when the total size of an operation is available.
Parameters:
- callback: the total callback to be used.
Warning
Deprecated: since v4.0. It is provided just for an easier transition from the old v3 API.
Sets whether the creator can update existing archives or not.
Note
If set to false, a subsequent compression operation may throw an exception if it targets an existing archive.
Parameters:
- canUpdate: if true, compressing operations will update existing archives.
[virtual] void setUpdateMode( UpdateMode mode )
Sets whether and how the creator can update existing archives or not.
Note
If set to UpdateMode::None, a subsequent compression operation may throw an exception if it targets an existing archive.
Parameters:
- mode: the desired update mode.
void setVolumeSize( std::uint64_t volumeSize ) noexcept
Sets the volumeSize (in bytes) of the output archive volumes.
Note
This setting has effects only when the destination archive is on the filesystem.
Parameters:
- volumeSize: The dimension of a volume.
void setWordSize( std::uint32_t wordSize )
Sets the word size to be used when creating/updating an archive.
Parameters:
- wordSize: the word size desired.
Returns whether the archive creator uses solid compression or not.
Returns true if the creator has been explicitly configured to store creation timestamps of items.
Returns true if the creator has been explicitly configured to store last access timestamps of items.
Returns true if the creator has been explicitly configured to store last write timestamps of items.
Returns whether the creator will attempt to compress files that are locked by other processes.
Returns whether the archive creator stores symbolic links as links in the output archive.
std::uint32_t threadsCount() const noexcept
Returns the number of threads used when creating/updating an archive (a zero value means that it will use the 7-zip default value).
const TotalCallback & totalCallback() const
Returns the current total callback.
UpdateMode updateMode() const noexcept
Returns the update mode used when updating existing archives.
std::uint64_t volumeSize() const noexcept
Returns the volume size (in bytes) used when creating multi-volume archives (a zero value means that all files are going in a single archive).
std::uint32_t wordSize() const noexcept
Returns the word size used for creating/updating an archive.
Copyright © Riccardo Ostani (@rikyoz)
- Bit7zLibrary
- BitArchiveEditor
- BitArchiveReader
- BitArchiveWriter
- BitException
- BitFileCompressor
- BitFileExtractor
- BitMemCompressor
- BitMemExtractor
- BitNestedArchiveReader
- BitStreamCompressor
- BitStreamExtractor
- BitInFormat