PrevNextUpHome BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1
SFXZIPDecoder
Storage class for decompressing the DEFLATE compressed data by gzip.
#include <SFXZIPDecoder.h.hpp>
class SFXZIPDecoder : public SFXStorage;
typedef SFXZIPDecoder&          SFXZIPDecoderRef;
typedef SFXZIPDecoder*          SFXZIPDecoderPtr;
typedef SFXZIPDecoder*&         SFXZIPDecoderPtrRef;
typedef SFXZIPDecoder**         SFXZIPDecoderHandle;
typedef const SFXZIPDecoder     ConstSFXZIPDecoder;
typedef const SFXZIPDecoder&    ConstSFXZIPDecoderRef;
typedef const SFXZIPDecoder*    ConstSFXZIPDecoderPtr;
typedef const SFXZIPDecoder*&   ConstSFXZIPDecoderPtrRef;
typedef const SFXZIPDecoder**   ConstSFXZIPDecoderHandle;

Inheritance diagram

 Inheritance diagram of SFXZIPDecoderClass

Collaboration diagram

 Collaboration diagram of SFXZIPDecoderClass

Description

Register the DEFLATE compressed data of storage class such as SFXFile, SFXTCPSocket, etc. or SFBSource class or SFBAStream class, and then get the decompressed data.

How to use the SFXZIPDecoder class

  1. Create the SFXZIPDecoder instance.
  2. Register the DEFLATE compressed data of a storage, SFBAStream, or SFBSource class by calling the SFXZIPDecoder::Open function.
  3. Get the input stream for reading data from ZIPDecoder using the SFXZIPDecoder::GetStreamReader function.
  4. Read the decompressed data through the input stream

Example 504. Sample code for decompress a gzip file

// define the SFXZIPDecoder instance, _decoder, as class member variable
class MyClass {
private:
    SFXFile _file;
    SFXZIPDecoder _decoder;             // SFXZIPDecoder instance
    SFXAnsiStringStreamReader  _reader; // input stream for reading data from ZIPDecoder
    SFXAnsiString _unzipString;         // variable in which decompressed string is stored
public:
    Void Start(Void);

    // callback function declaration
    CALLBACK_DECLARE_SFXANSISTRINGSTREAMREADER(OnFetch)
};

Void MyClass::Start(Void)
{
    SFCError error; // error value

    // open file in read only mode
    if ((error = _file.OpenReadOnly(SFXPath("/testdata.tar.gz")))
        == SFERR_NO_ERROR) {

        // register file storage in ZIPDecoder
        if ((error = _decoder.Open(_file)) == SFERR_NO_ERROR) {

            // get input stream for reading data from ZIPDecoder
            if ((error = _decoder.GetStreamReader(&_reader))
                == SFERR_NO_ERROR) {

                // read data from ZIPDecoder into input stream
                // OnFetch function is notified of the completion of this operation
                if ((error = _reader.Fetch(CALLBACK_FUNCTION(OnFetch)))
                    != SFERR_NO_ERROR) {
                    // if error occurs
                    _reader.Release();
                }
            }
            if (error != SFERR_NO_ERROR) { 
                // if error occurs
                _decoder.Close();
            }
        }
        if (error != SFERR_NO_ERROR) { 
            // if error occurs
            _file.Close();
        }
    }
}

// callback function notified after reading data from ZIPDecoder
CALLBACK_IMPLEMENT_SFXANSISTRINGSTREAMREADER(MyClass, OnFetch, error)
{
    if (error == SFERR_NO_ERROR) {  
        // if no error

        // read decompressed data from input stream to _unzipString variable
        if ((error = _reader.ReadSFXAnsiString(&_unzipString)) == SFERR_NO_ERROR) {

            // display decompressed data
            TRACE("%s", _unzipString.GetCString());
        }
    }
    // close
    _decoder.Close();
    _file.Close();
}

Reference

SFBAStream | SFBSource

Member

Constructor/Destructor
SFXZIPDecoder( Void )
Constructor of SFXZIPDecoder class.
~SFXZIPDecoder( Void )
Destructor of SFXZIPDecoder class.
Public Functions
SFCError AsSFBAStream( SFBAStreamSmpPtr result )
Convert the input stream used internally into the instance of SFBAStream class.
SFCError AsSFBSource( SFBSourceSmpPtr result )
Convert the input stream used internally into the instance of SFBSource class.
Void Cancel( Void )
Cancel the registered callback functions.
Void Close( Void )
Close the ZIPDecoder storage.
SFBUnzipAStreamSmpConstRef GetSFBUnzipAStream( Void )
Get the instance of SFBUnzipAStream class used internally.
SFCError GetStreamReader( UInt32 size , SFXStreamReaderPtr result )
GetStreamReader( SFXStreamReaderPtr result )
Get the input stream for reading data from ZIPDecoder.
SFCError GetStreamWriter( UInt32 size , SFXStreamWriterPtr result )
GetStreamWriter( SFXStreamWriterPtr result )
[ This function cannot be used now. ]
SFCError Open( SFXStorageConstRef storage )
Open( SFBSourceSmpConstRef source )
Open( SFBAStreamSmpConstRef stream )
Register the storage in the ZIPDecoder.
SFCError Read( VoidPtr buffer , UInt32Ptr size )
Read data from the ZIPDecorder storage without using the input stream..
SFCError ScheduleRead( CallbackSPP spp , VoidPtr reference )
Register callback function and schedule the reading.
SFCError ScheduleWrite( CallbackSPP spp , VoidPtr reference )
[ This function cannot be used now. ]
SFCError Write( VoidConstPtr buffer , UInt32Ptr size )
[ This function cannot be used now. ]
Types
CallbackSPP (inherits from SFXStorage)
The prototype of the callback function for the SFXStorage class.

SFXZIPDecoder::SFXZIPDecoder
Constructor of SFXZIPDecoder class.
[ public, explicit ]
SFXZIPDecoder(Void);

Description

SFBUnzipAStream interface is not reserved.


SFXZIPDecoder::~SFXZIPDecoder
Destructor of SFXZIPDecoder class.
[ public, virtual ]
virtual ~SFXZIPDecoder(Void);

Description

The SFXZIPDecoder::Close function is called.

Reference

SFXZIPDecoder::Close


SFXZIPDecoder::AsSFBAStream
Convert the input stream used internally into the instance of SFBAStream class.
[ public, virtual, const ]
SFCError AsSFBAStream(
    SFBAStreamSmpPtr result   // pointer that stores the result
);

Return value

  • Success : SFERR_NO_ERROR
  • If storage is not registered in the decoder (SFXZIPDecoder::Open function has not been called) : SFERR_INVALID_STATE
  • If argument is null : SFERR_INVALID_PARAM

Reference

SFBAStream


SFXZIPDecoder::AsSFBSource
Convert the input stream used internally into the instance of SFBSource class.
[ public, virtual, const ]
SFCError AsSFBSource(
    SFBSourceSmpPtr result   // pointer that stores the result
);

Return value

  • Success : SFERR_NO_ERROR
  • If storage is not registered in the decoder (SFXZIPDecoder::Open function has not been called) : SFERR_INVALID_STATE
  • If argument is null : SFERR_INVALID_PARAM
  • If failed to convert : SFERR_FAILED

Description

[Note] Note
The SFBSourceUtil class is internally used in the SFXZIPDecoder::AsSFBSource function.

Reference

SFBSource | SFBSourceUtil


SFXZIPDecoder::Cancel
Cancel the registered callback functions.
[ public, virtual ]
Void Cancel(Void);

Description

Cancel the callback functions registered in the instance of SFBUnzipAStream class used internally.

Reference

SFXZIPDecoder::Close | SFBUnzipAStream


SFXZIPDecoder::Close
Close the ZIPDecoder storage.
[ public ]
Void Close(Void);

Description

The register callback functions are canceled and the instance of SFBUnzipAStream class used internally is released.

Reference

SFXZIPDecoder::Cancel | SFBUnzipAStream


SFXZIPDecoder::GetSFBUnzipAStream
Get the instance of SFBUnzipAStream class used internally.
[ public, const ]
SFBUnzipAStreamSmpConstRef GetSFBUnzipAStream(Void);

Reference

SFBUnzipAStream


SFXZIPDecoder::GetStreamReader
Get the input stream for reading data from ZIPDecoder.
[ public, virtual ]
SFCError GetStreamReader(
    UInt32 size                 // buffer size
    SFXStreamReaderPtr result   // pointer to the input stream
);
[ public, virtual ]
SFCError GetStreamReader(
    SFXStreamReaderPtr result   // pointer to the input stream
);

Return value

  • Success : SFERR_NO_ERROR
  • If argument is null : SFERR_INVALID_PARAM
  • If source is not registered in the ZIPDecoder storage(SFXZIPDecoder::Open function has not been called) : SFERR_INVALID_STATE
  • If insuficient memory : SFERR_NO_MEMORY

Description

The buffer size of the input stream for reading data from ZIPDecorder can be specified. Use the SFXBinaryStreamReader, SFXAnsiStringStreamReader, or SFXWideStringStreamReader class for the input stream properly according to the type of data to read.

[Note] Note
Before calling the SFXZIPDecoder::GetStreamReader function, it is necessary to register the source using the SFXZIPDecoder::Open function.

Reference

SFXZIPDecoder::Open | SFXZIPDecoder::GetStreamWriter | SFXBinaryStreamReader | SFXAnsiStringStreamReader | SFXWideStringStreamReader


SFXZIPDecoder::GetStreamWriter
[ This function cannot be used now. ]
[ public, virtual ]
SFCError GetStreamWriter(
    UInt32 size                 // size
    SFXStreamWriterPtr result   // pointer to the output stream
);
[ public, virtual ]
SFCError GetStreamWriter(
    SFXStreamWriterPtr result   // pointer to the output stream
);

Description

SFERR_UNSUPPORTED is returned.


SFXZIPDecoder::Open
Register the storage in the ZIPDecoder.
[ public ]
SFCError Open(
    SFXStorageConstRef storage   // storage of data to decompress
);
[ public ]
SFCError Open(
    SFBAStreamSmpConstRef stream   // SFBAStream of data to decompress
);
[ public ]
SFCError Open(
    SFBSourceSmpConstRef source   // SFBSource of data to decompress
);

Return value

  • Success : SFERR_NO_ERROR
  • If storage has already been registered in the decoder : SFERR_INVALID_STATE
  • If argument is null : SFERR_INVALID_PARAM
  • If failed to open : SFERR_FAILED

Description

The instance of SFXStorage, SFBAStream or SFBSource class is set to the instance of SFBUnzipAStream class used internally.

Reference

SFXStorage | SFBAStream | SFBSource | SFBUnzipAStream


SFXZIPDecoder::Read
Read data from the ZIPDecorder storage without using the input stream..
[ public, virtual ]
SFCError Read(
    VoidPtr buffer   // buffer to read data from the ZIPDecorder storage
    UInt32Ptr size   // buffer size
);

Argument

buffer

Specify the buffer to read data from the ZIPDecorder storage.

size

Specify the size of buffer when calling SFXZIPDecoder::Read function. When the SFXZIPDecoder::Read function ends, the size of data that is actually read is stored.

Return value

  • Success : SFERR_NO_ERROR
  • If source is not registered in the ZIPDecoder storage (SFXZIPDecoder::Open has not been called) : SFERR_INVALID_STATE
  • If the size argument is null : SFERR_INVALID_PARAM
  • If necessary to retry : AEE_STREAM_WOULDBLOCK

Description

[Note] Note
Before calling the SFXZIPDecoder::Read function, it is necessary to register the source using the SFXZIPDecoder::Open function.

Reference

SFXZIPDecoder::Open


SFXZIPDecoder::ScheduleRead
Register callback function and schedule the reading.
[ public, virtual ]
SFCError ScheduleRead(
    CallbackSPP spp     // callback function
    VoidPtr reference   // data passed to callback function
);

Return value

  • Success : SFERR_NO_ERROR
  • If source is not registered in the ZIPDecoder storage (SFXZIPDecoder::Open has not been called), or the callback function has already been registered : SFERR_INVALID_STATE

Description

The SFXZIPDecoder::ScheduleRead function is used to register the callback function in which the SFXZIPDecoder::Read function is used to read data from the ZIPDecorder storage.

[Note] Note
When the return value of SFXZIPDecoder::Read function is AEE_STREAM_WOULDBLOCK, register the callback function using the SFXZIPDecoder::ScheduleRead function, and then schedule the SFXZIPDecoder::Read function in the callback function again.
[Note] Note
Before calling the SFXZIPDecoder::ScheduleRead function, it is necessary to register the source using the SFXZIPDecoder::Open function.

Reference

SFXZIPDecoder::Read | SFXZIPDecoder::Open


SFXZIPDecoder::ScheduleWrite
[ This function cannot be used now. ]
[ public, virtual ]
SFCError ScheduleWrite(
    CallbackSPP spp     // callback function
    VoidPtr reference   // data passed to callback
);

Description

SFERR_UNSUPPORTED is returned.


SFXZIPDecoder::Write
[ This function cannot be used now. ]
[ public, virtual ]
SFCError Write(
    VoidConstPtr buffer   // data size
    UInt32Ptr size        // data size
);

Description

SFERR_UNSUPPORTED is returned.