class BSByteStream: public ByteStream

Performs bzz compression/decompression.

Inheritance:


Public Methods

[more] BSByteStream(ByteStream &bs, int blocksize=0)
Constructs a BSByteStream.


Inherited from ByteStream:

Public Methods

ostatic GP<ByteStream> create(void)
ostatic GP<ByteStream> create(void const * const buffer, const size_t size)
ostatic GP<ByteStream> create( const char filename[], char const * const mode)
ostatic GP<ByteStream> create( const int fd, char const * const mode, const bool closeme)
ostatic GP<ByteStream> create( FILE * const f, char const * const mode, const bool closeme)
ostatic GP<ByteStream> create_static( void const * const buffer, const size_t size)

Public

class Stdioclass Staticclass Memoryclass Virtual Functions.

[more]virtual ~ByteStream()
Virtual destructor.
[more]virtual size_t read(void *buffer, size_t size)
Reads data from a ByteStream.
[more]virtual size_t write(const void *buffer, size_t size)
Writes data to a ByteStream.
[more]virtual long tell(void) const
Returns the offset of the current position in the ByteStream.
[more]virtual int seek(long offset, int whence = SEEK_SET, bool nothrow=false)
Sets the current position for reading or writing the ByteStream.
[more]virtual void flush(void)
Flushes all buffers in the ByteStream.

Utility Functions.

[more]size_t readall(void *buffer, size_t size)
Reads data and blocks until everything has been read.
[more]size_t writall(const void *buffer, size_t size)
Writes data and blocks until everything has been written.
[more]size_t copy(ByteStream &bsfrom, size_t size=0)
Copy data from another ByteStream.
[more]void write8(unsigned int card8)
Writes a one-byte integer to a ByteStream.
[more]void write16(unsigned int card16)
Writes a two-bytes integer to a ByteStream.
[more]void write24(unsigned int card24)
Writes a three-bytes integer to a ByteStream.
[more]void write32(unsigned int card32)
Writes a four-bytes integer to a ByteStream.
[more]unsigned int read8()
Reads a one-byte integer from a ByteStream.
[more]unsigned int read16()
Reads a two-bytes integer from a ByteStream.
[more]unsigned int read24()
Reads a three-bytes integer from a ByteStream.
[more]unsigned int read32()
Reads a four-bytes integer from a ByteStream.
[more]virtual int size(void) const
Returns the total number of bytes contained in the buffer, file, etc.
[more]TArray<char> get_data(void)
Use at your own risk, only guarenteed to work for ByteStream::Memorys.
[more]virtual size_t readat(void *buffer, size_t sz, int pos)
Reads data from a random position.


Inherited from GPEnabled:

Public Methods

oGPEnabled& operator=(const GPEnabled & obj)
oint get_count(void) const

Protected Fields

ovolatile int count


Documentation

Performs bzz compression/decompression.

Class BSByteStream defines a ByteStream which transparently performs the BZZ compression/decompression. The constructor of class BSByteStream takes another ByteStream as argument. Any data written to the BSByteStream is compressed and written to this second ByteStream. Any data read from the BSByteStream is internally generated by decompressing data read from the second ByteStream.

Program bzz demonstrates how to use this class. All the hard work is achieved by a simple ByteStream to ByteStream copy, as shown below.

      StdioByteStream in(infile,"rb");
      StdioByteStream out(outfile,"wb");
      if (encoding) {
          BSByteStream bsb(&out, blocksize);
          bsb.copy(in);
      } else {
          BSByteStream bsb(&in);
          out.copy(bsb);
      }
    
Due to the block oriented nature of the Burrows-Wheeler transform, there is a very significant latency between the data input and the data output. You can use function flush to force data output at the expense of compression efficiency.

You should never directly access a ByteStream object connected to a valid BSByteStream object. The ByteStream object can be accessed again after the destruction of the BSByteStream object. Note that the encoder always flushes its internal buffers and writes a few final code bytes when the BSByteStream object is destroyed. Note also that the decoder often reads a few bytes beyond the last code byte written by the encoder. This lag means that you must reposition the ByteStream after the destruction of the BSByteStream object and before re-using the ByteStream object (see IFFByteStream.)

o BSByteStream(ByteStream &bs, int blocksize=0)
Constructs a BSByteStream. Argument blocksize determines whether the BSByteStream will be used for compressing or decompressing data.
Decompression
Setting blocksize to zero initializes the decompressor. Chunks of data will be read from ByteStream bs and decompressed into an internal buffer. Function read can be used to access the decompressed data.
Compression
Setting blocksize to a positive number smaller than 4096 initializes the compressor. Data written to the BSByteStream will be accumulated into an internal buffer. The buffered data will be compressed and written to ByteStream bs whenever the buffer sizes reaches the maximum value specified by argument blocksize (in kilobytes). Using a larger block size usually increases the compression ratio at the expense of computation time. There is no need however to specify a block size larger than the total number of bytes to compress. Setting blocksize to 1024 is a good starting point. A minimal block size of 10 is silently enforced.


This class has no child classes.

Alphabetic index HTML hierarchy of classes or Java


DjVu is a trademark of LizardTech, Inc.
All other products mentioned are registered trademarks or trademarks of their respective companies.