Skip to content

BitMemCompressor

Oz edited this page Sep 3, 2019 · 18 revisions

The BitMemCompressor class allows to compress memory buffers to the filesystem or to other memory buffers. It let decide various properties of the produced archive file, such as the password protection and the compression level desired.

#include "bitmemcompressor.hpp"

inherits from BitArchiveCreator.

List of all members

Public Members

Return type Name
BitMemCompressor( Bit7zLibrary const &lib, BitInOutFormat const &format )
void compress( const vector< byte_t > &in_buffer, const wstring &out_file, const wstring &in_buffer_name=L"" ) const
void compress( const vector< byte_t > &in_buffer, vector< byte_t > &out_buffer, const wstring &in_buffer_name=L"" ) const
void compress( const vector< byte_t > &in_buffer, ostream &out_stream, const wstring &in_buffer_name=L"" ) const
const BitInFormat & format() const override
const BitInOutFormat & compressionFormat() const
bool cryptHeaders() const
BitCompressionLevel compressionLevel() const
BitCompressionMethod compressionMethod() const
uint32_t dictionarySize() const
bool solidMode() const
bool updateMode() const
uint64_t volumeSize() const
void setPassword( const wstring &password ) override
void setPassword( const wstring &password, bool crypt_headers )
void setCompressionLevel( BitCompressionLevel compression_level )
void setCompressionMethod( BitCompressionMethod compression_method )
void setDictionarySize( uint32_t dictionary_size )
void setSolidMode( bool solid_mode )
void setUpdateMode( bool update_mode )
void setVolumeSize( uint64_t size )
const Bit7zLibrary & library() const
const wstring password() const
bool isPasswordDefined() const
TotalCallback totalCallback() const
ProgressCallback progressCallback() const
RatioCallback ratioCallback() const
FileCallback fileCallback() const
PasswordCallback passwordCallback() const
void clearPassword()
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 )

Member Function Documentation

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

Constructs a BitMemCompressor object.

The Bit7zLibrary parameter is needed in order to have access to the functionalities of the 7z DLLs. On the other hand, the BitInOutFormat is required in order to know the format of the output archive.


void compress( const vector< byte_t > &in_buffer, const wstring &out_file, const wstring &in_buffer_name=L"" ) const

Compresses the given buffer to an archive on the filesystem.


void compress( const vector< byte_t > &in_buffer, vector< byte_t > &out_buffer, const wstring &in_buffer_name=L"" ) const

Compresses the given input buffer to the output buffer.

Note: If the format of the output doesn't support in memory compression, a BitException is thrown.


void compress( const vector< byte_t > &in_buffer, ostream &out_stream, const wstring &in_buffer_name=L"" ) const

Compresses the given input buffer to the output standard stream.

Note: If the format of the output doesn't support in memory compression, a BitException is thrown.


[virtual] const BitInFormat & format() const override

Returns the format used by the archive creator.


const BitInOutFormat & compressionFormat() const

Returns the format used by the archive creator.


bool cryptHeaders() const

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


BitCompressionLevel compressionLevel() const

Returns the compression level used by the archive creator.


BitCompressionMethod compressionMethod() const

Returns the compression method used by the archive creator.


uint32_t dictionarySize() const

Returns the dictionary size used by the archive creator.


bool solidMode() const

Returns whether the archive creator uses solid compression or not.


bool updateMode() const

Returns whether the archive creator is allowed to update existing archives or not.


uint64_t volumeSize() const

Returns the size (in bytes) of the archive volume used by the creator (a 0 value means that all files are going in a single archive).


[virtual] void setPassword( const wstring &password ) override

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. The option "crypt headers" remains unchanged, in contrast with what happens when calling the setPassword(wstring, 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).


void setPassword( const wstring &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, also the headers of the archive will be encrypted, resulting in a password request everytime 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).


void setCompressionLevel( BitCompressionLevel compression_level )

Sets the compression level to be used when creating an archive.


void setCompressionMethod( BitCompressionMethod compression_method )

Sets the compression method to be used when creating an archive.


void setDictionarySize( uint32_t dictionary_size )

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


void setSolidMode( bool solid_mode )

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.


void setUpdateMode( bool update_mode )

Sets whether the creator can update existing archives or not.

Note: If false, an exception will be thrown in case a compression operation targets an existing archive.


void setVolumeSize( uint64_t size )

Sets the size (in bytes) of the archive volumes.

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


const Bit7zLibrary & library() const

Returns the Bit7zLibrary object used by the handler.


const wstring password() const

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


bool isPasswordDefined() const

Returns true if a password is defined, false otherwise.


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.


void clearPassword()

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 setTotalCallback( const TotalCallback &callback )

Sets the callback to be called when the total size of an operation is available.


void setProgressCallback( const ProgressCallback &callback )

Sets the callback to be called when the processed size of the ongoing operation is updated.

Note: The percentage of completition of the current operation can be obtained by calculating static_cast( ( 100.0 * processed_size ) / total_size ).


void setRatioCallback( const RatioCallback &callback )

Sets the callback 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( ( 100.0 * output_size ) / input_size ).


void setFileCallback( const FileCallback &callback )

Sets the callback to be called when the currently file being processed changes.


void setPasswordCallback( const PasswordCallback &callback )

Sets the callback to be called when a password is needed to complete the ongoing operation.


Clone this wiki locally