zlib.js is ZLIB(RFC1950), DEFLATE(RFC1951), GZIP(RFC1952) and PKZIP implementation in JavaScript.
Usage
Use one in "bin" directory.
zlib_and_gzip.min.js: ZLIB + GZIP
(Raw)
rawdeflate.js: Raw Deflate
rawinflate.js: Raw Inflate
zlib.min.js: ZLIB Inflate + Deflate
inflate.min.js: ZLIB Inflate
deflate.min.js: ZLIB Deflate
inflate_stream.min.js: ZLIB Inflate (stream mode)
(GZIP)
gzip.min.js: GZIP
gunzip.min.js: GUNZIP
(PKZIP)
zip.min.js ZIP
unzip.min.js UNZIP
node-zlib.js: (ZLIB + GZIP for node.js)
Compression
Raw Deflate
// plain = Array.<number> or Uint8Arrayvar deflate = new Zlib.RawDeflate(plain);var compressed = deflate.compress();
Raw Deflate Option
See ZLIB Option.
ZLIB
// plain = Array.<number> or Uint8Arrayvar deflate = new Zlib.Deflate(plain);var compressed = deflate.compress();
ZLIB Option
Second argument of Zlib.Deflate constructor
{ compressionType: Zlib.Deflate.CompressionType, // compression type lazy: number // lazy matching parameter}
Zlib.Deflate.CompressionType is enumerable,
Choose one in NONE (Store), FIXED (Fixed Huffman Coding), DYNAMIC (Dynamic Huffman Coding).
Default value is DYNAMIC.
lazy is Lazy Matching length.
This parameter is deprecated.
GZIP
GZIP implementation is incomplete.
However, there is no problem in usual use.
// plain = Array.<number> or Uint8Arrayvar gzip = new Zlib.Gzip(plain);var compressed = gzip.compress();
var zip = new Zlib.Zip();// plainData1zip.addFile(plainData1, { filename: stringToByteArray('foo.txt')});zip.addFile(plainData2, { filename: stringToByteArray('bar.txt')});zip.addFile(plainData3, { filename: stringToByteArray('baz.txt')});var compressed = zip.compress();function stringToByteArray(str) { var array = new (window.Uint8Array !== void 0 ? Uint8Array :
PKZIP Option
filename, comment, extraField are must use Uint8Array if enabled Typed Array.
{ filename: (Array.<number>|Uint8Array), // filename comment: (Array.<number>|Uint8Array), //comment extraField: (Array.<number>|Uint8Array), // extra field compress: boolean, // compress when called "addFile" method. compressionMethod: Zlib.Zip.CompressionMethod, // STORE or DEFLATE os: Zlib.Zip.OperatingSystem, // MSDOS or UNIX or MACINTOSH deflateOption: Object // see: ZLIB Option}
Decompression
Raw Deflate
// compressed = Array.<number> or Uint8Arrayvar inflate = new Zlib.RawInflate(compressed);var plain = inflate.decompress();
Raw Deflate Option
See ZLIB Option.
ZLIB
// compressed = Array.<number> or Uint8Arrayvar inflate = new Zlib.Inflate(compressed);var plain = inflate.decompress();
ZLIB Option
Second argument of Zlib.Inflate constructor
{ 'index': number, // start position in input buffer 'bufferSize': number, // initial output buffer size 'bufferType': Zlib.Inflate.BufferType, // buffer expantion type 'resize': boolean, // resize buffer(ArrayBuffer) when end of decompression (default: false) 'verify': boolean // verify decompression result (default: false)}
Zlib.Inflate.BufferType is enumerable.
Choose one ADAPTIVE(default) and BLOCK.
ADAPTIVE: buffer expansion based on compression ratio in filled buffer.
BLOCK: buffer expansion based on BufferSize.
GZIP
// compressed = Array.<number> or Uint8Arrayvar gunzip = new Zlib.Gunzip(compressed);var plain = gunzip.decompress();
PKZIP
// compressed = Array.<number> or Uint8Arrayvar unzip = new Zlib.Unzip(compressed);var filenames = unzip.getFilenames();var plain = unzip.decompress(filenames[0]);