{"_id":"mozip","_rev":"28-af7ea3154b37b919534e1f7ef048bb21","name":"mozip","dist-tags":{"latest":"6.0.1"},"versions":{"6.0.0":{"name":"mozip","version":"6.0.0","keywords":["zip","archive","compress","async","promise"],"license":"MIT","_id":"mozip@6.0.0","maintainers":[{"name":"ijisol","email":"ijisol@naver.com"}],"homepage":"https://github.com/ijisol/mozip#readme","bugs":{"url":"https://github.com/ijisol/mozip/issues"},"dist":{"shasum":"89f74681f61e9e96555a092ffda909729af1074e","tarball":"https://registry.npmjs.org/mozip/-/mozip-6.0.0.tgz","fileCount":4,"integrity":"sha512-tBoquSxj4Twja6Yn9u6AcGRKYD3y0x5YV2xeuSasL7d15Vqw9DarX6tytxumsxjfSk1ma7OdPDjDddLKmrXxxg==","signatures":[{"sig":"MEUCIQCE1hvHmA8N5QHfT7nV6y09sGmidhnoGwkmuxkw8AUeOgIgPNF1OPa1UeopD1tstsa+CSESABDhEB/H61xOZhOtxIU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":22219},"type":"module","engines":{"node":">=22.10.0"},"exports":"./mozip.js","gitHead":"e886d65384a7d5b58fb15574886aa55ed02e3709","_npmUser":{"name":"ijisol","email":"ijisol@naver.com"},"repository":{"url":"git+https://github.com/ijisol/mozip.git","type":"git"},"_npmVersion":"12.0.1","description":"Minimal, zero-dependency library for generating ZIP archives with Node.js streams and a Promise-based API","directories":{},"_nodeVersion":"24.18.0","_hasShrinkwrap":false,"devDependencies":{"@types/node":"^24.13.3"},"_npmOperationalInternal":{"tmp":"tmp/mozip_6.0.0_1785152426346_0.5304658616097071","host":"s3://npm-registry-packages-npm-production"}},"6.0.1":{"name":"mozip","version":"6.0.1","description":"Minimal, zero-dependency library for generating ZIP archives with Node.js streams and a Promise-based API","keywords":["zip","archive","compress","async","promise"],"repository":{"type":"git","url":"git+https://github.com/ijisol/mozip.git"},"license":"MIT","author":{"name":"Lee Jisol","email":"ijisol@naver.com"},"type":"module","exports":"./mozip.js","engines":{"node":">=22.10.0"},"devDependencies":{"@types/node":"^24.13.3"},"gitHead":"d8cf4075cc30ddfab175dc6fe339a00e268c3870","_id":"mozip@6.0.1","bugs":{"url":"https://github.com/ijisol/mozip/issues"},"homepage":"https://github.com/ijisol/mozip#readme","_nodeVersion":"24.20.0","_npmVersion":"12.0.2","dist":{"integrity":"sha512-/Nxe9imRnVwGCYJZ0sNdmp9op902KS5EfkhKPYQw1RrbDzrxYV30iqQCQenYZUivWUfunWN8dqNY+4S0Pbj1Kw==","shasum":"9edae8d49ce06bd394cff68647c7bf8e6dddc40b","tarball":"https://registry.npmjs.org/mozip/-/mozip-6.0.1.tgz","fileCount":4,"unpackedSize":22351,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIFlhoq/kHArv6qRaK69lQzlF+wCaqCd7wAf0c0XdBe8TAiEA+VLoc3+tAvU1YlTM9GKrqbSGGsA9VnAm5+mrDa3xFlM="}]},"_npmUser":{"name":"ijisol","email":"ijisol@naver.com"},"directories":{},"maintainers":[{"name":"ijisol","email":"ijisol@naver.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/mozip_6.0.1_1787990196053_0.5223244329511214"},"_hasShrinkwrap":false}},"time":{"created":"2024-10-30T01:23:20.987Z","modified":"2026-08-29T07:56:36.345Z","1.0.0":"2024-10-28T15:18:27.508Z","1.0.1":"2024-10-30T01:23:21.195Z","1.0.2":"2024-10-30T04:43:11.871Z","1.0.3":"2024-10-30T07:06:52.800Z","1.0.4":"2024-11-23T10:30:51.469Z","2.0.0":"2024-12-14T01:41:02.420Z","3.0.0":"2025-01-27T09:32:43.193Z","3.0.1":"2025-01-28T05:39:01.791Z","5.0.0":"2026-06-17T05:25:01.703Z","5.1.0":"2026-07-23T13:23:12.499Z","5.1.1":"2026-07-24T06:02:39.426Z","5.1.2":"2026-07-24T07:09:17.150Z","6.0.0":"2026-07-27T11:40:26.505Z","6.0.1":"2026-08-29T07:56:36.174Z"},"bugs":{"url":"https://github.com/ijisol/mozip/issues"},"license":"MIT","homepage":"https://github.com/ijisol/mozip#readme","keywords":["zip","archive","compress","async","promise"],"repository":{"type":"git","url":"git+https://github.com/ijisol/mozip.git"},"description":"Minimal, zero-dependency library for generating ZIP archives with Node.js streams and a Promise-based API","maintainers":[{"name":"ijisol","email":"ijisol@naver.com"}],"readme":"# Mozip\n\nMinimal, single-file library for generating ZIP archives with Node.js streams and a Promise-based API\n\n- Zero dependencies except Node.js built-in modules\n- Implements a Node.js `Readable` stream\n- Supported compression methods: Store (no compression), Deflate\n- Configurable with zlib options (level, chunk size, etc.) for Deflate\n- UTF-8 filenames enforced\n\nNot supported:\n\n- ZIP64 (files >= 4 GiB, etc.)\n- Splitting or spanning archives\n- Configuring file attributes\n- Comments\n\n## Usage\n\n``` javascript\nimport { Buffer } from 'node:buffer';\nimport { writeFile } from 'node:fs/promises';\nimport { constants } from 'node:zlib';\nimport { ZipStream, dosDateTimeFrom } from 'mozip';\n\nconst zip = new ZipStream();\nconst finished = writeFile('example.zip', zip).catch((error) => {\n  console.error(error); // Stream or file writing error\n});\n\n// Files are added in `appendFile()` call order, though compression may run in parallel.\n// No need to await this unless parallel task management is needed.\nawait zip.appendFile('heavy/file', Buffer.alloc(2**31 - 1));\n\nconst data = Buffer.from('Hello, world!\\n'.repeat(2**16));\nzip.appendFile('compressed', data);\nzip.appendFile('stored', data, { compress: false });\nzip.appendFile('compressed/best', data, {\n  zlib: { level: constants.Z_BEST_COMPRESSION },\n});\n\nconst date = new Date('2000-01-02T01:23:45.678Z');\nzip.appendFile('timezone/local', data, { lastModified: date });\nzip.appendFile('timezone/UTC+9', data, {\n  lastModified: dosDateTimeFrom(date.getTime(), 9 * 60 * 60 * 1000),\n});\n\n// Rejects if a filename starts with a drive letter.\nzip.appendFile('C:\\\\file', data).catch(() => {\n  console.log('Skipped; the stream is still alive.');\n});\n\n// Must call `finalize()` after all files are added.\n// No need to await this unless the total size is needed.\nzip.finalize().then((byteLength) => {\n  if (byteLength < 0) return; // Failed to finalize\n  console.log(`Total size of the ZIP archive: ${byteLength} bytes`);\n});\n\nawait finished;\n```\n\n## Install\n\nInstall [mozip](https://www.npmjs.com/package/mozip) from the npm registry with your preferred package manager, such as:\n\n``` shell\nnpm install mozip\n```\n\nThen import the package:\n\n``` javascript\nimport { ZipStream, dosDateTimeFrom } from 'mozip';\n```\n\nAlternatively, download [mozip.js](https://github.com/ijisol/mozip/blob/latest/mozip.js) from the latest release and import it directly.\n\nIn Node.js, v22.2+ is required. Using the package in CommonJS modules requires v22.10+.\n\nAlso compatible with any runtime providing:\n\n- `Buffer` from `node:buffer`\n- `Readable` from `node:stream`\n- `promisify()` from `node:util`\n- `crc32()`, `deflateRaw()` from `node:zlib`\n- Global `Promise.withResolvers()`\n\n## API\n\n### `new ZipStream([options])`\n\n- Extends: [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable) from `node:stream`\n- `[options]`: `{Object}` Passed to the [`Readable` constructor](https://nodejs.org/api/stream.html#new-streamreadableoptions).\n\nCan be piped or passed to any consumer that accepts a `Readable`, such as `writeFile()` from `node:fs/promises`.\n\nStream errors are always emitted by the stream itself, never rejected within instance method calls.\n\nInstance fields not documented here should not be considered public API.\n\n### `ZipStream#validateFilename(name)`\n\n- `name`: `{string}` Filename\n- Returns: `{string}` Normalized filename\n\nNormalizes and validates a filename according to the minimum ZIP requirements. Removes leading slashes, throws an error if the name starts with a drive letter, and replaces backward slashes with forward slashes.\n\nCan be overridden to enforce stricter rules, such as [EPUB restrictions](https://www.w3.org/TR/epub-33/#sec-container-filenames).\n\n### `ZipStream#appendFile(name, data[, options])`\n\n- `name`: `{string}` Filename\n- `data`: `{TypedArray | DataView}` File data\n- `[options]`: `{Object}`\n  - `[compress]`: `{boolean}` Deflate if true, store if false. Defaults to true.\n  - `[lastModified]`: `{Date | number}` Last modified date/time of the file, defaults to the current local time. If an unsigned 32-bit integer, it is interpreted as MS-DOS date and time combined from high to low, as produced by `dosDateTimeFrom()`.\n  - `[zlib]`: `{node:zlib.Options}` Options for deflate compression. Implements the [`Options`](https://nodejs.org/api/zlib.html#class-options) interface from `node:zlib`.\n- Returns: `{Promise<boolean>}` Fulfills with true once the file header and data have been pushed to the internal read buffer, or false if the stream is destroyed while processing.\n\nAdds a file to the ZIP archive. Files are added in call order, though compression may run in parallel.\n\nDo not modify the contents of `data` after passing it; the view is compressed or written directly without being copied.\n\nEven when `options.compress` is true (the default), the file is stored if compressing did not reduce its size.\n\nTo set a specific time zone for `options.lastModified`, pass a value produced by `dosDateTimeFrom()`. By default, the local offset at the timestamp is used.\n\nRejected only before stream writing with:\n\n- `Error` if the stream has been destroyed, or `finalize()` was already called.\n- `RangeError` if 65535 (0xFFFF) files have already been added.\n- `TypeError` if any parameter has an invalid type.\n- `Error` if the filename starts with a drive letter.\n- `RangeError` if the filename length in UTF-8 bytes reaches or exceeds 64 KiB, or the file size reaches or exceeds 4 GiB.\n- `RangeError` if the archive size before the central directory or the central directory size would reach or exceed 4 GiB.\n\nErrors during writing are emitted by the stream.\n\n### `ZipStream#finalize()`\n\n- Returns: `{Promise<number>}` Fulfills with the total byte size of the archive, or -1 if the stream is destroyed while processing.\n\nFinalizes the ZIP archive by writing the central directory and ending the stream. Must be called after all files are added.\n\nRejected with an `Error` if the stream has been destroyed, `finalize()` was already called, or no files have been added.\n\nIf every file failed to be added, the stream is destroyed and an `Error` is emitted by the stream.\n\nThis does not wait for the stream to be completely consumed. To await complete stream consumption, `finished()` from `node:stream/promises` may be useful:\n\n``` javascript\nimport { finished } from 'node:stream/promises';\nimport { ZipStream } from 'mozip';\n\n/* ... */\n\nconst zip = new ZipStream();\nconst consumed = finished(zip);\n\n/* Pipe the stream, call `zip.appendFile()` more than once, etc. */\n\nzip.finalize();\ntry {\n  await consumed;\n  console.log('Stream consumed');\n} catch (error) {\n  console.error('Stream errored', error);\n}\n```\n\n### `dosDateTimeFrom(epochMilliseconds[, offsetMilliseconds])`\n\n- `epochMilliseconds`: `{number}` Milliseconds since the epoch (1970-01-01T00:00:00Z)\n- `[offsetMilliseconds]`: `{number}` UTC offset in milliseconds, defaults to the local time zone offset at `epochMilliseconds`\n- Returns: `{number}` Unsigned 32-bit integer combining [MS-DOS date and time](https://learn.microsoft.com/en-us/windows/win32/sysinfo/ms-dos-date-and-time) from high to low. Clamped to the MS-DOS date range of 1980 to 2107.\n\nUsed with the `options.lastModified` parameter of `ZipStream#appendFile()`. Useful for applying the same timestamp to multiple files, or setting a specific time zone.\n\nNote: The sign of `Date#getTimezoneOffset()` is opposite to that of the UTC offset.\n\n## Copyright\n\nCopyright (c) 2024 Lee Jisol \\<ijisol@naver.com>\n\nLicensed under the [MIT License](LICENSE).\n\n## Notes\n\nThe name Mozip is a pun; the Korean word 모집 (mo-jip) means gathering or collecting, and zip is written 집 in Hangul.\n","readmeFilename":"README.md","author":{"name":"Lee Jisol","email":"ijisol@naver.com"}}