Zip::ZipStatFilter Class Reference [Zip Code, Zip Code Internals]

#include <zipStatFilter.h>

Inheritance diagram for Zip::ZipStatFilter:

Inheritance graph
[legend]
List of all members.

Detailed Description

Helper class for tracking CRC and uncompressed size.

ZipStatFilter allows us to track CRC and uncompressed size on the fly. This is necessary when dealing with compressed files as the CRC must be of the uncompressed data.

ZipStatFilter is mostly intended for internal use by the zip code. However, it can be useful when reading zips sequentially using the stream interface to provide CRC checking.

Example

 // It's assumed that you would use proper error checking and that
 // zip is a valid pointer to a ZipArchive and otherStream is a pointer
 // to a valid stream.
 Zip::ZipArchive *zip;
 Stream *otherStream;
 
 // We need the real central directory to compare the CRC32
 Zip::CentralDir *realCD = zip->findFileInfo("file.txt");
 Stream *stream = zip->openFile("file.txt", ZipArchive::Read);
 
 Zip::CentralDir fakeCD;
 Zip::ZipStatFilter zsf(&fakeCD);
 
 zsf.attachStream(stream);
 
 // ... read <i>entire</i> file sequentially using zsf instead of stream
 otherStream->copyFrom(&zsf);
 
 zsf.detachStream();
 
 // fakeCD.mCRC32 now contains the CRC32 of the stream
 if(fakeCD.mCRC32 != realCD->mCRC32)
 {
    // ... handle CRC failure ...
 }
 
 zip->closeFile(stream);

A more complete example of this may be found in the code for the ZipArchive::extractFile() method in zipArchive.cc


Public Member Functions

 ZipStatFilter ()
 ZipStatFilter (CentralDir *cd)
virtual ~ZipStatFilter ()
virtual bool attachStream (Stream *stream)
virtual void detachStream ()
virtual StreamgetStream ()
void setCentralDir (CentralDir *cd)
CentralDirgetCentralDir ()

Protected Member Functions

virtual bool _write (const U32 numBytes, const void *buffer)
virtual bool _read (const U32 numBytes, void *buffer)

Protected Attributes

StreammStream
CentralDirmCD

Private Types

typedef FilterStream Parent


Member Typedef Documentation


Constructor & Destructor Documentation

Zip::ZipStatFilter::ZipStatFilter (  )  [inline]

Zip::ZipStatFilter::ZipStatFilter ( CentralDir cd  )  [inline]

virtual Zip::ZipStatFilter::~ZipStatFilter (  )  [inline, virtual]


Member Function Documentation

virtual bool Zip::ZipStatFilter::_write ( const U32  numBytes,
const void buffer 
) [inline, protected, virtual]

Reimplemented from FilterStream.

virtual bool Zip::ZipStatFilter::_read ( const U32  numBytes,
void buffer 
) [inline, protected, virtual]

Reimplemented from FilterStream.

virtual bool Zip::ZipStatFilter::attachStream ( Stream stream  )  [inline, virtual]

Implements FilterStream.

virtual void Zip::ZipStatFilter::detachStream (  )  [inline, virtual]

Implements FilterStream.

virtual Stream* Zip::ZipStatFilter::getStream (  )  [inline, virtual]

Implements FilterStream.

void Zip::ZipStatFilter::setCentralDir ( CentralDir cd  )  [inline]

CentralDir* Zip::ZipStatFilter::getCentralDir (  )  [inline]


Member Data Documentation