Menu

Home

Marian Edu

Zlib

Gzip encoding based on zlib library written by Jean-loup Gailly - http://www.zlib.net/

Depending on the target OS please select the right shared or dynamic library from http://www.zlib.net/.

If the zlib library is not already available on the system you might need to set the full path to the downloaded library in zlib-prototype.p.

Examples

    // compress a file, overwrite the output file if exists
    Zlib:getInstance(1000):compressFile('input.txt', 'output.zip', true).

    // compress string (character or longchar), raise error if the output file exists
    Zlib:getInstance():compress('uncompressed text', 'text.zip').

    // uncompress a file, overwrite the output file if exists
    Zlib:getInstance(10000):uncompressFile('input.zip', 'logo.png', true).

Copyright notice

Copyright © 2014 Marian Edu maria.nosp@m.n.edu@ganim.nosp@m.ede.ro

Released as open source courtesy of XPower http://www.xpower.be

License

This software is provided *’as-is’*, without any express or implied warranty.  In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

1.  The origin of this software must not be misrepresented; you must not claim that you wrote the original software.  If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.

2.  Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.

3.  This notice may not be removed or altered from any source distribution.

Summary

ZlibGzip encoding based on zlib library written by Jean-loup Gailly - http://www.zlib.net/
Properties
workBufferSizeThe default working buffer size.
Methods
getInstanceStatic method used to obtain a Zlib compression instance.
getInstanceStatic method used to obtain a Zlib compression instance, it will also set the default working buffer size on it.
compressCompresses the data from input string and returns a memory buffer holding compressed data.
compressCompresses the data from input memory buffer and returns a new buffer holding compressed data.
compressCompresses the data from input memory buffer and save the compressed data in a file using the gzip file format.
compressCompresses the data from input memory buffer and save the compressed data in a file using the gzip file format.
compressCompresses the data from input string and save the compressed data in a file using the gzip file format.
compressCompresses the data from input string and save the compressed data in a file using the gzip file format.
compressFileCompresses the data from the input file and save the compressed data in a file using the gzip file format.
compressFileCompresses the data from the input file and save the compressed data in a file using the gzip file format.
uncompressUncompresses the data from input memory buffer and return the uncompressed data in a new memory buffer.
uncompressUncompresses the data from input memory buffer and return the uncompressed data in a new memory buffer.
uncompressUncompresses the data from input memory buffer and save the uncompressed data in a file.
uncompressUncompresses the data from input memory buffer and save the uncompressed data in a file.
uncompressFileUncompresses the data from input gzip compressed file and save the uncompressed data in a file.
uncompressFileUncompresses the data from input gzip compressed file and save the uncompressed data in a file.

Properties

workBufferSize

define public property workBufferSize as int64

The default working buffer size.

Used by default for in-memory uncompress if destination buffer size is not specified and for file compression/uncompression to process file data in chunks.

Setting this to a lower values will have an important effect on compression/uncompression performance, to high values will lead to a greater memory usage during operations.

Default value is 100k bytes.

Methods

getInstance

method static public Zlib getInstance ()

Static method used to obtain a Zlib compression instance.

Returns

A instance of Zlib compression object (singleton).

getInstance

method static public Zlib getInstance (workBufferSize as int64)

Static method used to obtain a Zlib compression instance, it will also set the default working buffer size on it.

Parameters

The work buffer size of Zlib compression instance.

Returns

A instance of Zlib compression object (singleton).

compress

method public memptr compress (strData as longchar)

Compresses the data from input string and returns a memory buffer holding compressed data.

The memory location of returning buffer need to be freed by the caller.

Parameters

The input string (longchar or character) holding the data to be compressed.

Returns

A new memory buffer holding the compressed data.

See also

compressFile, uncompress, uncompressFile

compress

method public memptr compress (dataBuffer as memptr)

Compresses the data from input memory buffer and returns a new buffer holding compressed data.

The memory location of returning buffer need to be freed by the caller.

Parameters

The input memory buffer holding the data to be compressed.

Returns

A new memory buffer holding the compressed data.

See also

compressFile, uncompress, uncompressFile

compress

method public int64 compress (dataBuffer as memptr,
gzipPath as character)

Compresses the data from input memory buffer and save the compressed data in a file using the gzip file format.

If the output file exists this method will throw an error.

Parameters

  • The input memory buffer holding the data to be compressed.
  • The path of output compressed gzip file.

Returns

The size of compressed data written in gzip file, only the payload excluding gzip format additional information.

See also

compressFile, uncompress, uncompressFile

compress

method public int64 compress (dataBuffer as memptr,
gzipPath as character,
forceOverwrite as logical)

Compresses the data from input memory buffer and save the compressed data in a file using the gzip file format.

If forceOverwrite flag is set to false and the output file exists this method will throw an error, if set to true the file will be overwriten.

Parameters

  • The input memory buffer holding the data to be compressed.
  • The path of output compressed gzip file.
  • Force overwrite of output compressed gzip file.

Returns

The size of compressed data written in gzip file, only the payload excluding gzip format additional information.

See also

compressFile, uncompress, uncompressFile

compress

method public int64 compress (strData as longchar,
gzipPath as character)

Compresses the data from input string and save the compressed data in a file using the gzip file format.

If the output file exists this method will throw an error.

Parameters

  • The input string (longchar or character) holding the data to be compressed.
  • The path of output compressed gzip file.

Returns

The size of compressed data written in gzip file, only the payload excluding gzip format additional information.

See also

compressFile, uncompress, uncompressFile

compress

method public int64 compress (strData as longchar,
gzipPath as character,
forceOverwrite as logical)

Compresses the data from input string and save the compressed data in a file using the gzip file format.

If forceOverwrite flag is set to false and the output file exists this method will throw an error, if set to true the file will be overwriten.

Parameters

  • The input string (longchar or character) holding the data to be compressed.
  • The path of output compressed gzip file.
  • Force overwrite of output compressed gzip file.

Returns

The size of compressed data written in gzip file, only the payload excluding gzip format additional information.

See also

compressFile, uncompress, uncompressFile

compressFile

method public int64 compressFile (filePath as character,
gzipPath as character)

Compresses the data from the input file and save the compressed data in a file using the gzip file format.

If the output file exists this method will throw an error.

Parameters

  • The input file containing the data to be compressed.
  • The path of output compressed gzip file.

Returns

The size of compressed data written in gzip file, only the payload excluding gzip format additional information.

See also

compressFile, uncompress, uncompressFile

compressFile

method public int64 compressFile (filePath as character,
gzipPath as character,
forceOverwrite as logical)

Compresses the data from the input file and save the compressed data in a file using the gzip file format.

If forceOverwrite flag is set to false and the output file exists this method will throw an error, if set to true the file will be overwriten.

Parameters

  • The input file containing the data to be compressed.
  • The path of output compressed gzip file.
  • Force overwrite of output compressed gzip file.

Returns

The size of compressed data written in gzip file, only the payload excluding gzip format additional information.

See also

compress, uncompress, uncompressFile

uncompress

method public memptr uncompress (dataBuffer as memptr)

Uncompresses the data from input memory buffer and return the uncompressed data in a new memory buffer.

The default workBufferSize is set as the maximum size of uncompressed memory buffer.

If the destination maximum memory size is not large enough the method will raise an error.

Parameters

The input memory buffer holding the compressed data.

Returns

The new memory buffer holding uncompressed data, the caller is responsible of freeing it afterwards.

See also

compressFile, compress, uncompressFile

uncompress

method public memptr uncompress (dataBuffer as memptr,
bufferSize as int64)

Uncompresses the data from input memory buffer and return the uncompressed data in a new memory buffer.

If the destination maximum memory size is not large enough the method will raise an error.

Parameters

  • The input memory buffer holding the compressed data.
  • The maximum size of uncompressed memory buffer.

Returns

The new memory buffer holding uncompressed data, the caller is responsible of freeing it afterwards.

See also

compressFile, compress, uncompressFile

uncompress

method public int64 uncompress (dataBuffer as memptr,
filePath as character)

Uncompresses the data from input memory buffer and save the uncompressed data in a file.  If the output file exists this method will throw an error.

Parameters

  • The input memory buffer holding the compressed data.
  • The path of output file to uncompress into.

Returns

The size of uncompressed data written to output file.

See also

compressFile, compress, uncompressFile

uncompress

method public int64 uncompress (dataBuffer as memptr,
filePath as character,
forceOverwrite as logical)

Uncompresses the data from input memory buffer and save the uncompressed data in a file.  If the output file exists this method will throw an error.

Parameters

  • The input memory buffer holding the compressed data.
  • The path of output file to uncompress into.
  • Force overwrite of output file.

Returns

The size of uncompressed data written to output file.

See also

compressFile, compress, uncompressFile

uncompressFile

method public int64 uncompressFile (gzipPath as character,
filePath as character)

Uncompresses the data from input gzip compressed file and save the uncompressed data in a file.  If the output file exists this method will throw an error.

Parameters

  • The path of gzip file containing the compressed data.
  • The path of output file to uncompress into.

Returns

The size of uncompressed data written to output file.

See also

compressFile, compress, uncompress

uncompressFile

method public int64 uncompressFile (gzipPath as character,
filePath as character,
forceOverwrite as logical)

Uncompresses the data from input gzip compressed file and save the uncompressed data in a file.  If forceOverwrite flag is set to false and the output file exists this method will throw an error, if set to true the file will be overwriten.

Parameters

  • The path of gzip file containing the compressed data.
  • The path of output file to uncompress into.
  • Force overwrite of output file.

Returns

The size of uncompressed data written to output file.

See also

compressFile, compress, uncompress

Project Members:


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.