zlib processors for Kaitai Struct, with support for streams of unknown size.
# npm
npm install cp3-kaitai-zlib
# or yarn
yarn add cp3-kaitai-zlib# ./mydata.ksy
meta:
id: my-data
# ...etc, etc...
seq:
- id: example_data
size: 0
process: cp3.kaitai.zlib.inflate(_io)Click to expand
Decompresses the data. This will automatically detect gzip and zlib data (but not raw deflate data).
seq:
- id: glib_or_zlib_data_with_known_size
size: 80
process: cp3.kaitai.zlib.inflateDecompresses the data using the specified windowBits.
windowBits0To use the windowBits from the zlib header.- A number between
8and15for zlib. - A number between
-8and-15for raw deflate. - A number between
24and31for gzip. - A number between
40and47to auto-detect zlib and gzip. - See Notes on windowBits.
seq:
- id: raw_data_with_known_size
size: 80
process: cp3.kaitai.zlib.inflate(-15)Decompresses the stream until the stream ends or the end of the compressed data is reached. This will automatically detect gzip and zlib data (but not raw deflate data).
stream- The kaitai stream to read from.
seq:
- id: glib_or_zlib_data_with_unknown_size
size: 0
process: cp3.kaitai.zlib.inflate(_io)Decompresses the stream using the specified windowBits until the stream ends or the end of the compressed data is reached.
stream- The kaitai stream to read from.windowBits0To use the windowBits from the zlib header.- A number between
8and15for zlib. - A number between
-8and-15for raw deflate. - A number between
24and31for gzip. - A number between
40and47to auto-detect zlib and gzip. - See Notes on windowBits.
seq:
- id: glib_data_with_unknown_size
size: 0
process: cp3.kaitai.zlib.inflate(_io, 31)Click to expand
Decompresses raw deflate data.
seq:
- id: raw_data_with_known_size
size: 80
process: cp3.kaitai.zlib.inflate_rawDecompresses raw deflate data with the given windowBits. Note: this will automatically adjust windowBits for raw deflate decompression.
windowBits- A number between8and15. See Notes on windowBits.
seq:
- id: raw_data_with_known_size
size: 80
process: cp3.kaitai.zlib.inflate(15)Click to expand
Decompresses zlib data.
seq:
- id: zlib_data_with_known_size
size: 80
process: cp3.kaitai.zlib.inflate_zlibDecompresses the zlib stream until the stream ends or the end of the compressed data is reached.
stream- The kaitai stream to read from.
seq:
- id: zlib_data_with_unknown_size
size: 0
process: cp3.kaitai.zlib.inflate_zlib(_io)Decompresses zlib data using the specified windowBits. Note: this will automatically adjust windowBits for zlib decompression.
windowBits- A number between8and15. See Notes on windowBits.
seq:
- id: zlib_data_with_known_size
size: 80
process: cp3.kaitai.zlib.inflate_zlib(15)Decompresses the zlib stream using the specified windowBits until the stream ends or the end of the compressed data is reached. Note: this will automatically adjust windowBits for zlib decompression.
stream- The kaitai stream to read from.windowBits- A number between8and15. See Notes on windowBits.
seq:
- id: zlib_data_with_unnown_size
size: 0
process: cp3.kaitai.zlib.inflate_zlib(_io, 15)Click to expand
Decompresses gzip data.
seq:
- id: gzip_data_with_known_size
size: 80
process: cp3.kaitai.zlib.inflate_gzipDecompresses the gzip stream until the stream ends or the end of the compressed data is reached.
stream- The kaitai stream to read from.
seq:
- id: gzip_data_with_unknown_size
size: 0
process: cp3.kaitai.zlib.inflate_gzip(_io)Decompresses gzip data using the specified windowBits. Note: this will automatically adjust windowBits for gzip decompression.
windowBits- A number between8and15. See Notes on windowBits.
seq:
- id: gzip_data_with_known_size
size: 80
process: cp3.kaitai.gzip.inflate_gzip(15)Decompresses the gzip stream using the specified windowBits until the stream ends or the end of the compressed data is reached. Note: this will automatically adjust windowBits for gzip decompression.
stream- The kaitai stream to read from.windowBits- A number between8and15. See Notes on windowBits.
seq:
- id: gzip_data_with_unnown_size
size: 0
process: cp3.kaitai.zlib.inflate_gzip(_io, 15)The windowBits parameter in zlib is a bit confusing, here's what I know:
- The
windowBitsparameter is the base two logarithm of the window size (the size of the history buffer). windowBitsis a number in the range 8..15- The window size used for decompressing needs to be greater than or equal to the window size used to compress the data.
windowBitscan be adjusted to change the data format:- Left alone, data will be compressed/decompressed in zlib format (deflate data wrapped in a zlib header/trailer)
- Setting
windowBitsto 0 will use the window size from the zlib header.
- Setting
- Negating
windowBitswill compress/decompress data as raw deflate data (data with no header or trailer). - Adding 16 to
windowBitswill compress/decompress data in gzip format (deflate data wrapped in a gzip header/trailer) - Adding 32 to
windowBitswill automatically detect gzip or zlib format when decompressing data
- Left alone, data will be compressed/decompressed in zlib format (deflate data wrapped in a zlib header/trailer)
You can also check the zlib manual: https://www.zlib.net/manual.html#Advanced
This project is licensed under the MIT License - see the LICENSE.md file for details.