Added Zlib extraction

This commit is contained in:
n1474335 2019-01-11 17:58:25 +00:00
parent 4e57b4be88
commit 2307325af8
1 changed files with 32 additions and 1 deletions

View File

@ -828,7 +828,7 @@ export const FILE_SIGNATURES = {
0: 0x78,
1: [0x1, 0x9c, 0xda, 0x5e]
},
extractor: null
extractor: extractZlib
},
{
name: "xz compression",
@ -1443,6 +1443,37 @@ export function extractGZIP(bytes, offset) {
}
/**
* Zlib extractor.
*
* @param {Uint8Array} bytes
* @param {number} offset
* @returns {Uint8Array}
*/
export function extractZlib(bytes, offset) {
const stream = new Stream(bytes.slice(offset));
// Skip over CMF
stream.moveForwardsBy(1);
// Read flags
const flags = stream.readInt(1);
// Skip over preset dictionary checksum
if (flags & 0x20) {
stream.moveForwardsBy(4);
}
// Parse DEFLATE stream
parseDEFLATE(stream);
// Skip over final checksum
stream.moveForwardsBy(4);
return stream.carve();
}
/**
* Steps through a DEFLATE stream
*