mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
Add ZIP archive support to the node:zlib module through three classes and a set of helpers: - ZipEntry: a single archive member, with buffered reads (content()), bounded-memory streaming reads (contentIterator()), and create()/createStream() for building members. - ZipFile: random access to an archive backed by a file descriptor, reading members lazily without retaining their content and writing new members in place; opened with open()/openSync(). - ZipBuffer: a zero-copy, in-memory view over an archive already held in a Buffer. createZipArchive() serializes a sequence of entries into an archive byte stream, and setMaxZipContentSize() bounds the default in-memory decompression size. Every operation has both an asynchronous and a synchronous form. Signed-off-by: Philipp Dunkel <pip@pipobscure.com> PR-URL: https://github.com/nodejs/node/pull/64339 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh>
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
// The module-global default ceiling on in-memory member decompression, and
|
|
// its public getter/setter. Kept in its own module so every read path sees
|
|
// the one mutable value.
|
|
|
|
const { validateInteger } = require('internal/validators');
|
|
|
|
// A default ceiling on the uncompressed size that the buffering read paths
|
|
// (`ZipEntry.prototype.content()`, and therefore `ZipBuffer`/`ZipFile`
|
|
// `get()`) will materialize in memory when the caller does not pass an
|
|
// explicit `maxSize`. An archive whose central directory declares a member
|
|
// larger than this is rejected before any large allocation happens. Callers
|
|
// that need larger members can either pass a per-call `maxSize` or raise the
|
|
// module default with `setMaxZipContentSize()`. The streaming read paths
|
|
// (`contentIterator()`, `ZipFile.prototype.stream()`) are bounded-memory by
|
|
// design and are not subject to this default.
|
|
const DEFAULT_MAX_ZIP_CONTENT_SIZE = 256 * 1024 * 1024; // 256 MiB
|
|
let maxZipContentSize = DEFAULT_MAX_ZIP_CONTENT_SIZE;
|
|
|
|
/**
|
|
* @returns {number}
|
|
*/
|
|
function getMaxZipContentSize() {
|
|
return maxZipContentSize;
|
|
}
|
|
|
|
/**
|
|
* @param {number} size
|
|
* @returns {void}
|
|
*/
|
|
function setMaxZipContentSize(size) {
|
|
validateInteger(size, 'size', 0);
|
|
maxZipContentSize = size;
|
|
}
|
|
|
|
module.exports = {
|
|
DEFAULT_MAX_ZIP_CONTENT_SIZE,
|
|
getMaxZipContentSize,
|
|
setMaxZipContentSize,
|
|
};
|