PrevNextUpHome SophiaFramework UNIVERSE 5.3
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

The SFXZIPDecoder class is used to decompress the DEFLATE compressed data by gzip to be read from the SFBSource or SFBAStream instance or the storage such as SFXFile or SFXTCPSocket.

[Note] Limitation

Data can be read from the SFXZIPDecoder storage, but it cannot be written into this storage. The function to move the read pointer is not supported.

How to use the SFXZIPDecoder class

  1. Create the SFXZIPDecoder instance, i.e., the SFXZIPDecoder storage.
  2. Set the DEFLATE compressed storage, stream, or source to the SFXZIPDecoder storage with the SFXZIPDecoder::Open function.
  3. Get the input stream with the SFXZIPDecoder::GetStreamReader function.
  4. Read data from the SFXZIPDecoder storage using the input stream. At this time, the read data has already been decompressed.
  5. * If the input stream is not used, the decompressed data can be read from the SFXZIPDecoder storage with the SFXZIPDecoder::Read function.
  6. Close the SFXZIPDecoder storage with the SFXZIPDecoder::Close function.

Example 852. How to use the SFXZIPDecoder class

// _decoder is declared as class member variable since used the callback function
class MyClass {
private:
    SFXFile _file;                      // input file
    SFXZIPDecoder _decoder;             // gzip decoder
    SFXAnsiStringStreamReader  _reader; // input stream
    SFXAnsiString _unzipString;         // decompressed string
public:
    Void Start(Void);

    // callback function
    XALLBACK_DECLARE_SFXANSISTRINGSTREAMREADER(OnFetch)
};

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

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

        // set the file storage to the gzip decoder
        if ((error = _decoder.Open(_file)) == SFERR_NO_ERROR) {

            // get the input stream from the gzip decoder
            // * the stream buffer is variable since the size argument is not specified
            if ((error = _decoder.GetStreamReader(&_reader)) == SFERR_NO_ERROR) {

                // perform fetch: read the gzipped data from the gzip decoder into the stream buffer actually
                // *1. the fetch result will be notified to the OnFetch function
                // *2. the stream buffer will be expanded automatically depending on the size of data to be received
                if ((error = _reader.Fetch(XALLBACK_INTERNAL(OnFetch))) != SFERR_NO_ERROR) {

                    // if an error occurs
                    _reader.Release();
                }
            }
            if (error != SFERR_NO_ERROR) { 

                // if an error occurs
                _decoder.Close();
            }
        }
        if (error != SFERR_NO_ERROR) { 

            // if an error occurs
            _file.Close();
        }
    }
}

// callback function notified of the fetch result
XALLBACK_IMPLEMENT_SFXANSISTRINGSTREAMREADER(MyClass, OnFetch, error)
{
    if (error == SFERR_NO_ERROR) {  
        // if no error occurs in fetch

        // read data from the stream buffer into the _unzipString variable(at this time, data has already been decompressed)
        if ((error = _reader.ReadSFXAnsiString(&_unzipString)) == SFERR_NO_ERROR) {

            // display the _unzipString variable on BREW Output Window
            TRACE("%s", _unzipString.GetCString());

            _reader.Release();
        }
    }

    // termination
    _decoder.Close();
    _file.Close();
}

Reference

SFBAStream | SFBSource

Member

Constructor/Destructor
SFXZIPDecoder( Void )
Constructor of the SFXZIPDecoder class.
~SFXZIPDecoder( Void )
Destructor of the SFXZIPDecoder class.
Public Functions
SFCError AsSFBAStream( SFBAStreamSmpPtr result )
Convert the input stream used internally by this SFXZIPDecoder storage into the SFBAStream instance.
SFCError AsSFBSource( SFBSourceSmpPtr result )
Convert the input stream used internally by this SFXZIPDecoder storage into the SFBSource instance.
Void Cancel( Void )
Cancel the registered callback functions.
Void Close( Void )
Close this ZIPDecoder storage.
SFBUnzipAStreamSmpConstRef GetSFBUnzipAStream( Void )
Get the SFBUnzipAStream instance managed internally by this SFXZIPDecoder storage.
SFCError GetStreamReader( UInt32 size , SFXStreamReaderPtr result )
Get the input stream for reading data from this SFXZIPDecoder storage.
SFCError GetStreamReader( SFXStreamReaderPtr result )
Get the input stream for reading data from this SFXZIPDecoder storage.
SFCError GetStreamWriter( UInt32 size , SFXStreamWriterPtr result )
[This function cannot be used now.]
SFCError GetStreamWriter( SFXStreamWriterPtr result )
[This function cannot be used now.]
SFCError Open( SFXStorageConstRef storage )
Set the specified compressed stream, storage or source to this SFXZIPDecoder storage.
SFCError Open( SFBAStreamSmpConstRef stream )
Set the specified compressed stream, storage or source to this SFXZIPDecoder storage.
SFCError Open( SFBSourceSmpConstRef source )
Set the specified compressed stream, storage or source to this SFXZIPDecoder storage.
SFCError Read( VoidPtr buffer , UInt32Ptr size )
Read data from this ZIPDecoder without input stream.
SFCError ScheduleRead( CallbackSPP spp , VoidPtr reference )
Schedule to read data from this ZIPDecoder without input stream.
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)
Type of the callback function for the Storage class.

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

Description

This constructor does nothing.


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

Description

This destructor calls the SFXZIPDecoder::Close function.

[Note] Note

Registered callback functions will be canceled.

Reference

SFXZIPDecoder::Close


SFXZIPDecoder::AsSFBAStream
Convert the input stream used internally by this SFXZIPDecoder storage into the SFBAStream instance.
[ public, virtual, const ]
SFCError AsSFBAStream(
    SFBAStreamSmpPtr result   // pointer to the SFBAStream instance
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this SFXZIPDecoder storage has been closed: SFERR_INVALID_STATE
  • If the result argument is null: SFERR_INVALID_PARAM

Description

This function converts the input stream used internally by this SFXZIPDecoder storage into the SFBAStream instance.

As a result, a pointer to the SFBAStream instance will be returned into the result argument.

[Note] Note
The contents of the SFXZIPDecoder storage can be handled as the SFBAStream instance.

Reference

SFXZIPDecoder::Open | SFBUnzipAStream | SFBAStream


SFXZIPDecoder::AsSFBSource
Convert the input stream used internally by this SFXZIPDecoder storage into the SFBSource instance.
[ public, virtual, const ]
SFCError AsSFBSource(
    SFBSourceSmpPtr result   // pointer to the SFBSource instance
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this SFXZIPDecoder storage has been closed: SFERR_INVALID_STATE
  • If the result argument is null: SFERR_INVALID_PARAM

Description

This function converts the input stream used internally by this SFXZIPDecoder storage into the SFBSource instance.

As a result, a pointer to the SFBSource instance will be returned into the result argument.

[Note] Note

This function internally calls the BREW API ISOURCEUTIL_SourceFromAStream function.

[Note] Note
The contents of the SFXZIPDecoder storage can be handled as the SFBSource instance.

Reference

SFXZIPDecoder::Open | SFBUnzipAStream | SFBSource | SFBSourceUtil | BREW API ISOURCEUTIL_SourceFromAStream


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

Description

This function cancels scheduling with the SFXZIPDecoder::ScheduleRead function.

The registered callback functions will be canceled.

[Note] Note

This function is called in the SFXZIPDecoder::Close function.

Reference

SFXZIPDecoder::ScheduleRead | SFXZIPDecoder::Close


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

Description

This function closes (or finishes) this ZIPDecoder storage.

Concretely, this function calls the SFXZIPDecoder::Cancel function and releases the SFBUnzipAStream instance that this ZIPDecoder storage internally manages.

[Note] Note

The registered callback functions will be canceled.

[Note] Note

This function is called in the SFXZIPDecoder::~SFXZIPDecoder destructor.

[Tip] Tip

When suspending, resources should be released by calling this function.

Reference

SFXZIPDecoder::Cancel | SFXZIPDecoder::~SFXZIPDecoder | SFXZIPDecoder::Open | SFBUnzipAStream


SFXZIPDecoder::GetSFBUnzipAStream
Get the SFBUnzipAStream instance managed internally by this SFXZIPDecoder storage.
[ public, const ]
SFBUnzipAStreamSmpConstRef GetSFBUnzipAStream(Void);

Return value

SFBUnzipAStream instance managed internally by this SFXZIPDecoder storage.

Description

This function gets the SFBUnzipAStream instance managed internally by this SFXZIPDecoder storage.

Reference

SFBUnzipAStream | BREW API IUnzipAStream


SFXZIPDecoder::GetStreamReader
Get the input stream for reading data from this SFXZIPDecoder storage.
[ 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

  • If succeeds: SFERR_NO_ERROR
  • If the result argument is null: SFERR_INVALID_PARAM
  • If no source is registered in this SFXZIPDecoder storage with the SFXZIPDecoder::Open function: SFERR_INVALID_STATE
  • If insuficient memory: SFERR_NO_MEMORY

Description

This function gets the input stream for reading data from this SFXZIPDecoder storage.

If the size argument is specified, the buffer size of the input stream will be fixed with the specified value. Otherwise, the buffer size will be variable and the SFXElasticStreamReader class will be used internally.

[Tip] Tip
You have to use the SFXBinaryStreamReader, SFXAnsiStringStreamReader, or SFXWideStringStreamReader class for the input stream properly depending on the type of data to be read.
[Caution] Caution
Before calling this function, you have to register the source into this SFXZIPDecoder storage with the SFXZIPDecoder::Open function.

Reference

SFXZIPDecoder::Open | SFXBinaryStreamReader | SFXAnsiStringStreamReader | SFXWideStringStreamReader | Stream Buffer


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
);

Return value

SFERR_UNSUPPORTED

Description

[This function cannot be used now.]

Reference

SFXZIPDecoder::GetStreamReader


SFXZIPDecoder::Open
Set the specified compressed stream, storage or source to this SFXZIPDecoder storage.
[ public ]
SFCError Open(
    SFXStorageConstRef storage   // storage to be decoded
);
[ public ]
SFCError Open(
    SFBAStreamSmpConstRef stream   // stream to be decoded
);
[ public ]
SFCError Open(
    SFBSourceSmpConstRef source   // source to be decoded
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If stream, storage or source has already been set: SFERR_INVALID_STATE
  • If argument is null: SFERR_INVALID_PARAM

Description

This function sets the specified compressed stream, storage or source as the source for the SFBUnzipAStream instance that this SFXZIPDecoder storage manages internally.

The SFXStorage, SFBAStream or SFBSource instance can be specified in the argument.

After this function is executed, the gzipped data will be read and decoded at the same time by using the input stream obtained with the SFXZIPDecoder::GetStreamReader function or by calling the SFXZIPDecoder::Read function.

[Note] Note

This function internally calls the SFBUnzipAStream::SetStream function to set the specified compressed stream, storage or source as the source for the SFBUnzipAStream instance that this SFXZIPDecoder storage manages internally.

At this time, the storage and the source internally will be converted into the stream with the AsSFBAStream function and the SFBSourceUtil::AStreamFromSource function respectively.

Reference

SFBUnzipAStream::SetStream | SFXZIPDecoder::Close | SFXZIPDecoder::GetStreamReader | SFXZIPDecoder::Read | SFXStorage | SFBAStream | SFBSource | SFBUnzipAStream | BREW API IUNZIPASTREAM_SetStream


SFXZIPDecoder::Read
Read data from this ZIPDecoder without input stream.
[ public, virtual ]
SFCError Read(
    VoidPtr buffer   // buffer to read data
    UInt32Ptr size   // before this function is called: size of the data to read; just after this function is returned: size of the data to be read actually
);

Argument

buffer

Specify the buffer to read data.

size

Before calling this function, specify the buffer size to read data. Just after this function is returned, the size of data to be read actually will be stored into this argument.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this file has not been opened: SFERR_INVALID_STATE
  • If the size argument is null: SFERR_INVALID_PARAM
  • If retry is necessary: AEE_STREAM_WOULDBLOCK

Description

This function reads data from this ZIPDecoder without input stream.

When all data has been read from this ZIPDecoder, this function will return SFERR_NO_ERROR and 0 will be returned into the area that the size argument points to.

* If this function returns AEE_STREAM_WOULDBLOCK, it will be necessary to register a callback function with the SFXZIPDecoder::ScheduleRead function where data will be read with this function.

[Note] Note

This function internally calls the SFBAStream::Read function.

[Note] Prerequisite

This ZIPDecoder needs to be opened (or set) with the SFXZIPDecoder::Open function before this function is called.

Reference

SFXZIPDecoder::Open | SFXZIPDecoder::ScheduleRead | SFBAStream::Read | BREW API IUNZIPASTREAM_Read


SFXZIPDecoder::ScheduleRead
Schedule to read data from this ZIPDecoder without input stream.
[ public, virtual ]
SFCError ScheduleRead(
    CallbackSPP spp     // callback function
    VoidPtr reference   // data passed to callback function
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this ZIPDecoder is not opened (or set) with the SFXZIPDecoder::Open function, or reading data has already been scheduled: SFERR_INVALID_STATE

Description

This function schedules to read data from this ZIPDecoder without input stream.

Concretely, this function registers the callback function that will read data with the SFXZIPDecoder::Read function. The registered callback function will be called by BREW AEE when it is possible to read data.

The status of this ZIPDecoder is "under scheduling to read data" until the callback function is called. And after the callback function is called, it will become the status before calling this function, i.e., "this ZIPDecoder is opened".

If you call the SFXZIPDecoder::Cancel function before the callback function is called, reading data will be canceled and the status will be returned to the status before calling this function, i.e., "this ZIPDecoder is opened".

*1. If the SFXZIPDecoder::Read function returns AEE_STREAM_WOULDBLOCK, it will be necessary to register a callback function with this function where data will be read with the SFXZIPDecoder::Read function.

*2. If this function returns the value other than SFERR_NO_ERROR, the specified callback function will not be called.

[Note] Note

This function internally calls the SFBAStream::Readable function.

[Note] Prerequisite

This ZIPDecoder needs to be opened (or set) with the SFXZIPDecoder::Open function before this function is called.

And if this ZIPDecoder has been already scheduled to read data, the SFERR_INVALID_STATE error will be returned.

Reference

SFXZIPDecoder::Read | SFXZIPDecoder::Open | SFXZIPDecoder::Cancel | SFBAStream::Readable | SFXStorage::CallbackSPP | BREW API IUNZIPASTREAM_Readable


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

Return value

SFERR_UNSUPPORTED

Description

[This function cannot be used now.]

Reference

SFXStorage::CallbackSPP


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

Return value

SFERR_UNSUPPORTED

Description

[This function cannot be used now.]