{"name":"@tokenizer/inflate","version":"0.3.0","keywords":["zip","unzip","decompress","inflate","strtok3","tokenizer","stream","S3"],"author":{"url":"https://github.com/Borewit","name":"Borewit"},"license":"MIT","_id":"@tokenizer/inflate@0.3.0","maintainers":[{"name":"borewit","email":"borewit@xs4all.nl"}],"homepage":"https://github.com/Borewit/tokenizer-inflate#readme","bugs":{"url":"hhttps://github.com/Borewit/tokenizer-inflate/issues"},"dist":{"shasum":"74d5de2a66e5b429834b31eef09fbc3191b4055a","tarball":"http://registry-npm.ywwl.com/@tokenizer/inflate/download/@tokenizer/inflate-0.3.0.tgz","fileCount":11,"integrity":"sha512-hs32YCvUxSjTmCg9gzNvMUo8vny7FCEEZtIiAK+G4WXgRuuQUbbe0cZO/eHlPm+1k1yEnNbtOwTpFwu7Pk/Lyw==","signatures":[{"sig":"MEQCICMV/zM0oyMOmjDY5bQvRieb8eXPhZu758Hy57UUh/mvAiBDM/Xn19rEmYYhuqP6vxxqnowGqSS7zVx/mvKEv8Zb5A==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":28539,"size":7677,"noattachment":false,"key":"/@tokenizer/inflate/-/@tokenizer/inflate-0.3.0.tgz"},"type":"module","engines":{"node":">=18"},"exports":"./lib/index.js","funding":{"url":"https://github.com/sponsors/Borewit","type":"github"},"gitHead":"cc4e9098a67abe1157d3a6c66b23458e9a33fcaa","scripts":{"fix":"yarn run biome lint --write","test":"mocha","build":"yarn run clean && yarn run compile","clean":"del-cli 'lib/**/*.js' 'lib/**/*.js.map' 'lib/**/*.d.ts' 'test/**/*.js' 'test/**/*.js.map'","start":"yarn run compile && yarn run lint && yarn run cover-test","eslint":"eslint lib test","compile":"yarn run compile-src && yarn run compile-test","lint:md":"remark -u preset-lint-recommended .","lint:ts":"biome check","compile-src":"tsc -p lib","compile-test":"tsc -p test"},"_npmUser":{"name":"borewit","email":"borewit@xs4all.nl"},"repository":{"url":"git+https://github.com/Borewit/tokenizer-inflate.git","type":"git"},"_npmVersion":"11.3.0","description":"Tokenized zip support","directories":{},"_nodeVersion":"22.13.0","dependencies":{"debug":"^4.4.1","fflate":"^0.8.2","token-types":"^6.0.0"},"_hasShrinkwrap":false,"packageManager":"yarn@4.9.1","devDependencies":{"chai":"^5.2.0","mocha":"^11.1.0","del-cli":"^6.0.0","strtok3":"^10.2.2","ts-node":"^10.9.2","file-type":"^21.0.0","typescript":"^5.8.3","@types/chai":"^5.2.2","@types/node":"^22.15.21","@types/debug":"^4","@types/mocha":"^10.0.10","@tokenizer/s3":"^1.0.1","@biomejs/biome":"=1.9.4","@aws-sdk/client-s3":"^3.787.0"},"_npmOperationalInternal":{"tmp":"tmp/inflate_0.3.0_1749152972605_0.3822785028227731","host":"s3://npm-registry-packages-npm-production"},"readme":"[![Node.js CI](https://github.com/Borewit/tokenizer-inflate/actions/workflows/nodejs-ci.yml/badge.svg)](https://github.com/Borewit/tokenizer-inflate/actions/workflows/nodejs-ci.yml)\n[![NPM version](https://badge.fury.io/js/%40tokenizer%2Finflate.svg)](https://npmjs.org/package/@tokenizer/inflate)\n[![npm downloads](https://img.shields.io/npm/dm/@tokenizer%2Finflate.svg)](https://npmcharts.com/compare/%40tokenizer%2Finflate?start=1200&interval=30)\n\n# @tokenizer/inflate\n\n`@tokenizer/inflate` is a package designed for handling and extracting data from ZIP files efficiently using a tokenizer-based approach.\nThe library provides a customizable way to parse ZIP archives and extract compressed data while minimizing memory usage.\n\n## Features\n- Efficient Decompression: Handles streams compressed with DEFLATE and related formats (e.g., gzip).\n- Tokenizer Compatibility: Seamlessly integrates with [strtok3](https://github.com/Borewit/strtok3). For example, use  [@tokenizer/s3](https://github.com/Borewit/tokenizer-s3) for efficient partial extraction of a Zip stored on AWS S3 cloud file storage.\n- Streamlined Interface: Provides an intuitive API for working with compressed data in streaming and random-access scenarios.\n- Chunked Data Access: Leverages the underlying media's capabilities to offer chunked or random access to data, unlike traditional streams.\n- Plug-and-Play: Easily integrate with existing tokenizer-based workflows for parsing file metadata or binary structures.\n- Interrupt the extraction process conditionally.\n\n## Installation\n```bash\nnpm install @tokenizer/inflate\n```\n\n## Usage\n\n### Example: Extracting Specific Files\n\nThe following example demonstrates how to use the library to extract .txt files and stop processing when encountering a .stop file.\n\n```js\nimport { ZipHandler } from '@tokenizer/inflate';\nimport { fromFile } from 'strtok3';\n\nconst fileFilter = (file) => {\n  console.log(`Processing file: ${file.filename}`);\n\n  if (file.filename?.endsWith(\".stop\")) {\n    console.log(`Stopping processing due to file: ${file.filename}`);\n    return { handler: false, stop: true }; // Stop the unzip process\n  }\n\n  if (file.filename?.endsWith(\".txt\")) {\n    return {\n      handler: async (data) => {\n        console.log(`Extracted text file: ${file.filename}`);\n        console.log(new TextDecoder().decode(data));\n      },\n    };\n  }\n\n  return { handler: false }; // Ignore other files\n};\n\nasync function extractFiles(zipFilePath) {\n  const tokenizer = await fromFile(zipFilePath);\n  const zipHandler = new ZipHandler(tokenizer);\n  await zipHandler.unzip(fileFilter);\n}\n\nextractFiles('example.zip').catch(console.error);\n```\n\n## API\n\n### `ZipHandler`\nA class for handling ZIP file parsing and extraction.\n#### Constructor\n```ts\nnew ZipHandler(tokenizer: ITokenizer)\n```\n- **tokenizer**: An instance of ITokenizer to read the ZIP archive.\n#### Methods\n \n- `isZip(): Promise<boolean>`\n\n   Determines whether the input file is a ZIP archive.\n\n- `unzip(fileCb: InflateFileFilter): Promise<void>`\n\n  Extracts files from the ZIP archive, applying the provided `InflateFileFilter` callback to each file.\n\n```InflatedDataHandler``` \n\n## Types\n\n### `InflateFileFilter`\n```ts\ntype InflateFileFilter = (file: IFullZipHeader) => InflateFileFilterResult;\n```\nCallback function to determine whether a file should be handled or ignored.\n\n### `InflateFileFilterResult`\n```ts\ntype InflateFileFilterResult = {\n  handler: InflatedDataHandler | false; // Handle file data or ignore\n  stop?: boolean; // Stop processing further files\n};\n\n```\nReturned from `InflateFileFilter` to control file handling and extraction flow.\n\n### `InflatedDataHandler`\n```ts\ntype InflatedDataHandler = (fileData: Uint8Array) => Promise<void>;\n```\nHandler for processing uncompressed file data.\n\n## Compatibility\n\nThis module is a [pure ECMAScript Module (ESM)](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).\nThe distributed JavaScript codebase is compliant with the [ECMAScript 2020 (11th Edition)](https://en.wikipedia.org/wiki/ECMAScript_version_history#11th_Edition_%E2%80%93_ECMAScript_2020) standard.\nIf used with Node.js, it requires version ≥ 18.\n\n## License\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.","publish_time":1749152972791,"_cnpm_publish_time":1749152972791,"dist-tags":{"latest":"0.6.0"}}