tar
Version:
tar for JavaScript
35 lines • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.gzip = void 0;
/**
* Gzip with the `DecompressionStream` and `CompressionStream` of the
* runtime. The async readers always have it, after `opt.codecs`.
* The option `portable` of `compress` makes output that does not
* name the system.
*/
exports.gzip = {
name: 'gzip',
headLength: 2,
detect: head => head[0] === 0x1f && head[1] === 0x8b,
decompress: () => new DecompressionStream('gzip'),
compress: options => {
const stream = new CompressionStream('gzip');
if (!options?.portable)
return stream;
// Byte 9 of a gzip stream names the system that made it. Set it
// to 255, "unknown", so that each system makes the same bytes.
let pos = 0;
return {
writable: stream.writable,
readable: stream.readable.pipeThrough(new TransformStream({
transform: (chunk, controller) => {
if (pos <= 9 && pos + chunk.length > 9)
chunk[9 - pos] = 255;
pos += chunk.length;
controller.enqueue(chunk);
},
})),
};
},
};
//# sourceMappingURL=codec.js.map