My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
jsz  
jsz module
doc
Updated May 31, 2009 by sou...@gmail.com

If something seems wrong or incomplete, please enter a comment at the bottom of this page.



- source - main - QA -

jsz module

This module manage zlib data compression and decompression. more.


jsz::Z class

constructor

  • Constructor( method [, compressionLevel ] )
  • Constructs a new inflater or deflater object.

    The
    method can be Z.DEFLATE to compress data or Z.INFLATE to decompress data. The compression level is like this: 0 <= compressionLevel <= 9.
    note:
    For Z.INFLATE method, compressionLevel argument is useless ( no sense )
    example:
      var compress = new Z( Z.DEFLATE, 9 );

call operator

string call operator( [ inputData [, forceFinish = false ] ] )
This function process inputData as a stream. If forceFinish is true, the inputData and any buffered data are flushed to the outputData. If this function is call without any argument, All remaining data are flushed. Once finished, the object can be reused to process a new stream of data.
example:
  var compress = new Z( Z.DEFLATE );
  var compressedData = compress( 'Hello ');
  compressedData += compress( 'world' );
  compressedData += compress(); // flush
example:
  var compress = new Z( Z.DEFLATE );
  var compressedData = compress( 'Hello ');
  compressedData += compress( 'world', true ); // flush
example:
  var compressedData = new Z( Z.DEFLATE )( 'Hello world', true ); // flush

Properties

idle

boolean idle
Is true if the redy to process new data.

adler32

  • dler32
  • Contains the adler32 checksum of the data. more.

lengthIn

  • engthIn
  • Contains the current total amount of input data.

lengthOut

  • engthOut
  • Contains the current total amount of output data.

Static Properties

Constants

  • Z.DEFLATE
  • Compression method.
  • Z.INFLATE
  • Decompression method.

example

var deflate = new Z( Z.DEFLATE, 9 );
var clearData;
var compressedData;

for ( var i = 10; i >= 0; --i ) {

   var chunk = randomString(10000);
   compressedData += deflate( chunk );
   clearData += chunk;
}
compressedData += deflate(); // flush


var inflate = new Z( Z.INFLATE );
var clearData2 = inflate( compressedData, true );

Print( 'ratio:' + compressedData.length + ': ' + Math.round( 100 * compressedData.length / clearData.length ) + '%','\n');
if ( clearData2 != clearData )

   Print('error!!!','\n');
}

code snippet


jsz::ZError class

You cannot construct this class.

Its aim is to throw as an exception on any zlib runtime error.

- top - main -


Sign in to add a comment
Powered by Google Project Hosting