Qt LZO Classes and Functions


Table Of Contents

  1. class QtLzo
  2. class ScriptableLzo
  3. QtLzo functions


class QtLzo

Functionality

Compress and Decompress LZO data blocks.

Declaration

class QtLzo
{
  public:

    typedef enum      {
      LZO1x      =  1 ,
      LZO1       =  2 ,
      LZO1_99    =  3 ,
      LZO1a      =  4 ,
      LZO1a_99   =  5 ,
      LZO1b      =  6 ,
      LZO1b_99   =  7 ,
      LZO1b_999  =  8 ,
      LZO1c      =  9 ,
      LZO1c_99   = 10 ,
      LZO1c_999  = 11 ,
      LZO1f_1    = 12 ,
      LZO1f_999  = 13 ,
      LZO1x_1    = 14 ,
      LZO1x_1_11 = 15 ,
      LZO1x_1_12 = 16 ,
      LZO1x_1_15 = 17 ,
      LZO1x_999  = 18 ,
      LZO1y_1    = 19 ,
      LZO1y_999  = 20 ,
      LZO1z_999  = 21 ,
      LZO2a_999  = 22 }
      LzoMethods      ;

    explicit     QtLzo   (void) ;
    virtual     ~QtLzo   (void) ;

    virtual bool isLZO   (QByteArray & header) ;

    virtual void CleanUp (void) ;

    virtual bool IsCorrect          (int returnCode) ;
    virtual bool IsEnd              (int returnCode) ;
    virtual bool IsFault            (int returnCode) ;

    virtual int  BeginCompress      (int level = 9,int method = LZO1x) ;
    virtual int  BeginCompress      (QVariantList arguments = QVariantList() ) ;
    virtual int  doCompress         (const QByteArray & Source      ,
                                           QByteArray & Compressed) ;
    virtual int  doSection          (      QByteArray & Source      ,
                                           QByteArray & Compressed) ;
    virtual int  CompressDone       (QByteArray & Compressed) ;

    virtual int  BeginDecompress    (void) ;
    virtual int  doDecompress       (const QByteArray & Source        ,
                                           QByteArray & Decompressed) ;
    virtual int  undoSection        (      QByteArray & Source        ,
                                           QByteArray & Decompressed) ;
    virtual int  DecompressDone     (void) ;

    virtual bool IsTail             (QByteArray & header) ;

  protected:

    void * LzoPacket ;

    virtual void CompressHeader     (QByteArray & Compressed) ;
    virtual void CompressTail       (unsigned int checksum,QByteArray & Compressed) ;
    virtual int  DecompressHeader   (const QByteArray & Source) ;

  private:

};

Explanation


Enumeration

LzoMethods

Name
Value
Action
LZO1x
1
Use LZO1 X compression method.
LZO1
2
Use LZO1 general compression method.
LZO1_99
3
Use LZO1-99 compression method.
LZO1a
4
Use LZO1a general compression method.
LZO1a_99
5
Use LZO1a-99 compression method.
LZO1b
6
Use LZO1b general compression method.
LZO1b_99
7
Use LZO1b-99 compression method.
LZO1b_999
8
Use LZO1b-999 compression method.
LZO1c
9
Use LZO1c general compression method.
LZO1c_99
10
Use LZO1c-99 compression method.
LZO1c_999
11
Use LZO1c-999 compression method.
LZO1f_1
12
Use LZO1f-1 compression method.
LZO1f_999
13
Use LZO1f-999 compression method.
LZO1x_1
14
Use LZO1x-1 compression method.
LZO1x_1_11
15
Use LZO1x-1-11 compression method.
LZO1x_1_12
16
Use LZO1x-1-12 compression method.
LZO1x_1_15
17
Use LZO1x-1-15 compression method.
LZO1x_999
18
Use LZO1x-999 compression method.
LZO1y_1
19
Use LZO1y-1 compression method.
LZO1y_999
20
Use LZO1y-999 compression method.
LZO1z_999
21
Use LZO1z-999 compression method.
LZO2a_999
22
Use LZO2a-999 compression method.


bool isLZO(QByteArray & header)

Determine if header is a LZO file format header.

LZO file format header is 7 bytes, as following :
0
1
2
3
4
5
6
7
0x00
0xE9
0x4C
0x5A
0x4F
0xFF
0x1A



void CleanUp (void)

Clean up LzoPacket for reuse.  If you are goin to reuse QtLzo after compression or decompression, before the second loop, you better call CleanUp() once.


bool IsCorrect(int returnCode)

Determine if the return code is at the correct condition.


bool IsEnd(int returnCode)

Determine if the return code is at the completed condition.


bool IsFault(int returnCode)

Determine if the return code is at the fault condition.


int BeginCompress(int level,int method) ;

Set up compression parameters.

  1. level : 1~9, default value is 9
  2. method : lzoMethods, default value is LZO1x

int BeginCompress(QVariantList arguments)

Set up compression parameters.

  1. level : 1~9, default value is 9
  2. method : lzoMethods, default value is LZO1x
  3. blocks : size of each memory block, default value is 8192
  4. output length : output length, default value is 0

int doCompress(const QByteArray & Source,QByteArray & Compressed)

Compress Source into Compressed to be LZO compressed format.  This function only need to be called once, the whole memory data block will be packed into a completed LZO file format.  This function is mostly used when you are sure about the size of the original memory data block.

return the condition code of compression.


int doSection(QByteArray & Source,QByteArray & Compressed)

Compress Source data block into Compressed data block, into LZO compressed format.  This function is to compress the source data by small packages, mostly used when you are not sure about the total size of original data, such as real time network data exchange.

You are required to call CompressDone after completed data compression.

This function will remove the data from Source data block at the beginning position, the size of removal is compressed source data block.

return the condition code of compression.


int CompressDone(QByteArray & Compressed)

You are required to call this function to fill the tail data block when using doSection compression method.


int BeginDecompress(void)

Prepare for decompression


int doDecompress(const QByteArray & Source,QByteArray & Decompressed)

Decompress LZO Source into Decompressed memory data block, Source is basically a completed LZO file format.

return the condition code of decompress.


int undoSection(QByteArray & Source,QByteArray & Decompressed)

Decompress LZO Source into Decompressed memory data block, into original source data.  This function is to decompress the LZO data by small packages, mostly used when you are not sure about the total size of LZO data size, such as real time network data exchange.

You are required to call DecompressDone after completed data decompression.

This function will remove the data from Source at the beginning position, the size of removal is decompressed LZO data block.

return the condition code of decompress.


int DecompressDone(void)

After decompression completed, you are required to call this function.


bool IsTail(QByteArray & header)

Determine if this is a LZO file format tail.


void CompressHeader(QByteArray & Compressed)

Generate LZO compressed file format header.


void CompressTail(unsigned int checksum,QByteArray & Compressed)

Generate LZO file format tail. checksum is ADLER32。


int DecompressHeader(const QByteArray & Source)

Verify if Source is a LZO file header, and return the beginning position of the memory data block.


class ScriptableLzo

Functionality

In Qt Script Javascript, object to handle LZO compression and decompression.

Declaration

class ScriptableLzo : public QObject
                 , public QScriptable
                 , public QtLzo
{
  Q_OBJECT
  public:

    explicit     ScriptableLzo (QObject * parent) ;
    virtual     ~ScriptableLzo (void) ;

  protected:

  private:

  public slots:

    virtual bool ToLzo         (QString file,QString lzo,int level = 9,int method = QtLzo::LZO1x) ;
    virtual bool ToFile        (QString lzo,QString file) ;

  protected slots:

  private slots:

  signals:

};

Explanation


bool ToLzo(QString file,QString lzo,int level,int method)

Compress file into lzo, return true when success, otherwise return false.

Parameters:
  1. file : Original source file.
  2. lzo : LZO compressed file format
  3. level : 1~9, default value is 9.
  4. method : lzoMethods, default value is LZO1x.


bool ToFile(QString lzo,QString file)

Decompress lzo into file, return true when success, otherwise return false.


QtLzo functions

There are currently 6 functions in Qt LZO.


Explanation


bool ToLZO (const QByteArray & data,QByteArray & lzo,int level,int method)

Compress memory data block into LZO compressed format, return when success, otherwise return false.

Parameters :
  1. data : memory data block
  2. lzo : LZO compressed format
  3. level : 1~9, default value is 9
  4. method : lzoMethods, default value is LZO1x

bool FromLZO (const QByteArray & lzo ,QByteArray & data)

Decompress LZO data block into original data block, return when success, otherwise return false.

Parameters :
  1. lzo : LZO compressed data block
  2. data : Original source data block

bool SaveLZO (QString filename,QByteArray & data,int level,int method)

Compress memory data block into LZO compressed format, and save into file, return when success, otherwise return false.

Parameters :
  1. filename : LZO filename
  2. data : Original source data
  3. level : 1~9, default value is 9
  4. method : lzoMethods, default value is LZO1x

bool LoadLZO (QString filename,QByteArray & data)

Decompress LZO file into original source data, return when success, otherwise return false.

Parameters :
  1. filename : LZO filename
  2. data : Original source data

bool FileToLzo (QString file,QString lzo,int level,int method)

Compress file into lzo, return when success, otherwise return false.

Parameters :
  1. file : Original data file
  2. lzo : LZO compressed file format
  3. level : 1~9, default value is 9
  4. method : lzoMethods, default value is LZO1x


bool LzoToFile (QString lzo,QString file)

Decompress lzo into file, return when success, otherwise return false.



Neutrino International Inc. 2001~2015