Skip to content

BitStreamCompressor

Oz edited this page Jan 20, 2023 · 9 revisions

Alias for BitCompressor< std::istream & >.

The BitStreamCompressor alias allows compressing data from standard input streams.

The compressed archives can be saved to the filesystem, standard streams, or memory buffers.

#include <bit7z/bitstreamcompressor.hpp>

List of all members

Public Members

Return type Name
BitCompressor( Bit7zLibrary const& lib, BitInOutFormat const& format )
void compressFile( std::istream& in_file, const tstring& out_file, const tstring& input_name = {} ) const
void compressFile( std::istream& in_file, vector< byte_t >& out_buffer, const tstring& input_name = {} ) const
void compressFile( std::istream& in_file, ostream& out_stream, const tstring& input_name = {} ) const
const BitInFormat & format() const noexcept override
const BitInOutFormat & compressionFormat() const noexcept
bool cryptHeaders() const noexcept
BitCompressionLevel compressionLevel() const noexcept
BitCompressionMethod compressionMethod() const noexcept
uint32_t dictionarySize() const noexcept
uint32_t wordSize() const noexcept
bool solidMode() const noexcept
UpdateMode updateMode() const noexcept
uint64_t volumeSize() const noexcept
uint32_t threadsCount() const noexcept
void setPassword( const tstring& password ) override
void setPassword( const tstring& password, bool crypt_headers )
void setCompressionLevel( BitCompressionLevel level ) noexcept
void setCompressionMethod( BitCompressionMethod method )
void setDictionarySize( uint32_t dictionary_size )
void setWordSize( uint32_t word_size )
void setSolidMode( bool solid_mode ) noexcept
void setUpdateMode( UpdateMode mode )
void setUpdateMode( bool can_update )
void setVolumeSize( uint64_t volume_size ) noexcept
void setThreadsCount( uint32_t threads_count ) noexcept
void setFormatProperty( const wchar_t( &name )[N], T value ) noexcept
void setFormatProperty( const wchar_t( &name )[N], const T& value ) noexcept
const Bit7zLibrary & library() const noexcept
tstring password() const
bool retainDirectories() const noexcept
bool isPasswordDefined() const noexcept
TotalCallback totalCallback() const
ProgressCallback progressCallback() const
RatioCallback ratioCallback() const
FileCallback fileCallback() const
PasswordCallback passwordCallback() const
OverwriteMode overwriteMode() const
void clearPassword() noexcept
void setRetainDirectories( bool retain ) noexcept
void setTotalCallback( const TotalCallback& callback )
void setProgressCallback( const ProgressCallback& callback )
void setRatioCallback( const RatioCallback& callback )
void setFileCallback( const FileCallback& callback )
void setPasswordCallback( const PasswordCallback& callback )
void setOverwriteMode( OverwriteMode mode )

Member Function Documentation

BitCompressor( Bit7zLibrary const& lib, BitInOutFormat const& format )

Constructs a BitCompressor object. The Bit7zLibrary parameter is needed to have access to the functionalities of the 7z DLLs. On the contrary, the BitInOutFormat is required to know the format of the output archive.

Parameters:

  • lib: the 7z library to use.
  • format: the output archive format.

void compressFile( std::istream& in_file, const tstring& out_file, const tstring& input_name = {} ) const

Compresses a single file.

Parameters:

  • in_file: the file 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.

void compressFile( std::istream& in_file, vector< byte_t >& out_buffer, const tstring& input_name = {} ) const

Compresses the input file to the output buffer.

Parameters:

  • in_file: the file to be compressed.
  • out_buffer: the buffer going to contain the output archive.
  • input_name: (optional) the name to give to the compressed file inside the output archive.

void compressFile( std::istream& in_file, ostream& out_stream, const tstring& input_name = {} ) const

Compresses the input file to the output stream.

Parameters:

  • in_file: the file to be compressed.
  • out_stream: the output stream.
  • input_name: (optional) the name to give to the compressed file inside the output archive.

[virtual] const BitInFormat & format() const noexcept override

Returns the format used for creating/updating an archive.

const BitInOutFormat & compressionFormat() const noexcept

Returns the format used for creating/updating an archive.

bool cryptHeaders() const noexcept

Returns whether the creator crypts also the headers of archives or not.

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.

uint32_t dictionarySize() const noexcept

Returns the dictionary size used for creating/updating an archive.

uint32_t wordSize() const noexcept

Returns the word size used for creating/updating an archive.

bool solidMode() const noexcept

Returns whether the archive creator uses solid compression or not.

UpdateMode updateMode() const noexcept

Returns the update mode used when updating existing archives.

uint64_t volumeSize() const noexcept

Returns the volume size (in bytes) used when creating multi-volume archives (a 0 value means that all files are going in a single archive).

uint32_t threadsCount() const noexcept

Returns the number of threads used when creating/updating an archive (a 0 value means that it will use the 7-zip default value).

[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).

Parameters:

  • password: the password to be used when creating/updating archives.

void setPassword( const tstring& password, bool crypt_headers )

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 "crypt_headers" 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).

Parameters:

  • password: the password to be used when creating/updating archives.
  • crypt_headers: if true, the headers of the output archives will be encrypted (valid only when using the 7z format).

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( uint32_t dictionary_size )

Sets the dictionary size to be used when creating/updating an archive.

Parameters:

  • dictionary_size: the dictionary size desired.

void setWordSize( uint32_t word_size )

Sets the word size to be used when creating/updating an archive.

Parameters:

  • word_size: the word size desired.

void setSolidMode( bool solid_mode ) noexcept

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:

  • solid_mode: if true, it will be used the "solid compression" method.

[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 setUpdateMode( bool can_update )

Sets whether the creator can update existing archives or not. Deprecated: since v4.0; it is provided just for an easier transition from the old v3 API.

Note: If set to false, a subsequent compression operation may throw an exception if it targets an existing archive.

Parameters:

  • can_update: if true, compressing operations will update existing archives.

void setVolumeSize( uint64_t volume_size ) noexcept

Sets the volume_size (in bytes) of the output archive volumes.

Note: This setting has effects only when the destination archive is on the filesystem.

Parameters:

  • volume_size: The dimension of a volume.

void setThreadsCount( uint32_t threads_count ) noexcept

Sets the number of threads to be used when creating/updating an archive.

Parameters:

  • threads_count: the number of threads desired.

void setFormatProperty( const wchar_t(&) name, T value ) noexcept

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 setFormatProperty( const wchar_t(&) name, const T& value ) noexcept

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.

const Bit7zLibrary & library() const noexcept

Returns the Bit7zLibrary object used by the handler.

tstring password() const

Returns the password used to open, extract, or encrypt the archive.

bool retainDirectories() const noexcept

Returns a boolean value indicating whether the directory structure must be preserved while extracting or compressing the archive.

bool isPasswordDefined() const noexcept

Returns a boolean value indicating whether a password is defined or not.

TotalCallback totalCallback() const

Returns the current total callback.

ProgressCallback progressCallback() const

Returns the current progress callback.

RatioCallback ratioCallback() const

Returns the current ratio callback.

FileCallback fileCallback() const

Returns the current file callback.

PasswordCallback passwordCallback() const

Returns the current password callback.

OverwriteMode overwriteMode() const

Returns the current OverwriteMode.

void clearPassword() noexcept

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"").

void setRetainDirectories( bool retain ) noexcept

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

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.

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.

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.

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 setOverwriteMode( OverwriteMode mode )

Sets how the handler should behave when it tries to output to an existing file or buffer.

Parameters:

Clone this wiki locally