{"name":"@tokenizer/inflate","version":"0.2.6","keywords":["zip","unzip","decompress","inflate","strtok3","tokenizer","stream","S3"],"author":{"url":"https://github.com/Borewit","name":"Borewit"},"license":"MIT","_id":"@tokenizer/inflate@0.2.6","homepage":"https://github.com/Borewit/tokenizer-inflate#readme","bugs":{"url":"hhttps://github.com/Borewit/tokenizer-inflate/issues"},"dist":{"shasum":"259a8c46648a0ff245f7a52a7c4c6cb569b75701","tarball":"http://registry-npm.ywwl.com/@tokenizer/inflate/download/@tokenizer/inflate-0.2.6.tgz","fileCount":7,"integrity":"sha512-SdR/i05U7Xhnsq36iyIq/ZiGGw4PKzw4ww3bOq80Pjj4wyXpqyTcgrgdDdGlcatnlvzNJx8CQw3hp6QZvkUwhA==","signatures":[{"sig":"MEUCIAzc8meFnmPeJjKsYIBv6thWWSQ0ZySoaRgNTrbVQnvcAiEAtoTJjydz0LsIf2mgyUp41lkT/h20aTBjRqIB6X/inPA=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":26521,"size":7198,"noattachment":false,"key":"/@tokenizer/inflate/-/@tokenizer/inflate-0.2.6.tgz"},"type":"module","engines":{"node":">=16"},"exports":"./lib/index.js","funding":{"url":"https://github.com/sponsors/Borewit","type":"github"},"gitHead":"ab2e5846bf6593a45b8824108e4bd741d3fbf714","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":"10.8.2","description":"Tokenized zip support","directories":{},"_nodeVersion":"20.17.0","dependencies":{"debug":"^4.3.7","fflate":"^0.8.2","token-types":"^6.0.0"},"_hasShrinkwrap":false,"packageManager":"yarn@4.3.1","devDependencies":{"chai":"^5.1.2","mocha":"^10.8.2","del-cli":"^6.0.0","strtok3":"^10.0.1","ts-node":"^10.9.2","file-type":"^19.6.0","typescript":"^5.7.2","@types/chai":"^5.0.1","@types/node":"^22.9.3","@types/debug":"^4","@types/mocha":"^10.0.10","@tokenizer/s3":"^0.5.1","@biomejs/biome":"=1.9.4","@aws-sdk/client-s3":"^3.705.0"},"_npmOperationalInternal":{"tmp":"tmp/inflate_0.2.6_1733575948428_0.7739236118525681","host":"s3://npm-registry-packages"},"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)\r\n[![NPM version](https://badge.fury.io/js/%40tokenizer%2Finflate.svg)](https://npmjs.org/package/@tokenizer/inflate)\r\n[![npm downloads](https://img.shields.io/npm/dm/@tokenizer%2Finflate.svg)](https://npmcharts.com/compare/%40tokenizer%2Finflate?start=1200&interval=30)\r\n\r\n# @tokenizer/inflate\r\n\r\n`@tokenizer/inflate` is a package designed for handling and extracting data from ZIP files efficiently using a tokenizer-based approach.\r\nThe library provides a customizable way to parse ZIP archives and extract compressed data while minimizing memory usage.\r\n\r\n## Features\r\n- Efficient Decompression: Handles streams compressed with DEFLATE and related formats (e.g., gzip).\r\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.\r\n- Streamlined Interface: Provides an intuitive API for working with compressed data in streaming and random-access scenarios.\r\n- Chunked Data Access: Leverages the underlying media's capabilities to offer chunked or random access to data, unlike traditional streams.\r\n- Plug-and-Play: Easily integrate with existing tokenizer-based workflows for parsing file metadata or binary structures.\r\n- Interrupt the extraction process conditionally.\r\n\r\n## Installation\r\n```bash\r\nnpm install @tokenizer/inflate\r\n```\r\n\r\n## Usage\r\n\r\n### Example: Extracting Specific Files\r\n\r\nThe following example demonstrates how to use the library to extract .txt files and stop processing when encountering a .stop file.\r\n\r\n```js\r\nimport { ZipHandler } from '@tokenizer/inflate';\r\nimport { fromFile } from 'strtok3';\r\n\r\nconst fileFilter = (file) => {\r\n  console.log(`Processing file: ${file.filename}`);\r\n\r\n  if (file.filename?.endsWith(\".stop\")) {\r\n    console.log(`Stopping processing due to file: ${file.filename}`);\r\n    return { handler: false, stop: true }; // Stop the unzip process\r\n  }\r\n\r\n  if (file.filename?.endsWith(\".txt\")) {\r\n    return {\r\n      handler: async (data) => {\r\n        console.log(`Extracted text file: ${file.filename}`);\r\n        console.log(new TextDecoder().decode(data));\r\n      },\r\n    };\r\n  }\r\n\r\n  return { handler: false }; // Ignore other files\r\n};\r\n\r\nasync function extractFiles(zipFilePath) {\r\n  const tokenizer = await fromFile(zipFilePath);\r\n  const zipHandler = new ZipHandler(tokenizer);\r\n  await zipHandler.unzip(fileFilter);\r\n}\r\n\r\nextractFiles('example.zip').catch(console.error);\r\n```\r\n\r\n## API\r\n\r\n### `ZipHandler`\r\nA class for handling ZIP file parsing and extraction.\r\n#### Constructor\r\n```ts\r\nnew ZipHandler(tokenizer: ITokenizer)\r\n```\r\n- **tokenizer**: An instance of ITokenizer to read the ZIP archive.\r\n#### Methods\r\n \r\n- `isZip(): Promise<boolean>`\r\n\r\n   Determines whether the input file is a ZIP archive.\r\n\r\n- `unzip(fileCb: InflateFileFilter): Promise<void>`\r\n\r\n  Extracts files from the ZIP archive, applying the provided `InflateFileFilter` callback to each file.\r\n\r\n```InflatedDataHandler``` \r\n\r\n## Types\r\n\r\n### `InflateFileFilter`\r\n```ts\r\ntype InflateFileFilter = (file: IFullZipHeader) => InflateFileFilterResult;\r\n```\r\nCallback function to determine whether a file should be handled or ignored.\r\n\r\n### `InflateFileFilterResult`\r\n```ts\r\ntype InflateFileFilterResult = {\r\n  handler: InflatedDataHandler | false; // Handle file data or ignore\r\n  stop?: boolean; // Stop processing further files\r\n};\r\n\r\n```\r\nReturned from `InflateFileFilter` to control file handling and extraction flow.\r\n\r\n### `InflatedDataHandler`\r\n```ts\r\ntype InflatedDataHandler = (fileData: Uint8Array) => Promise<void>;\r\n```\r\nHandler for processing uncompressed file data.\r\n\r\n## Compatibility\r\n\r\nThis module is a [pure ECMAScript Module (ESM)](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).\r\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.\r\nIf used with Node.js, it requires version ≥ 18.\r\n\r\n## License\r\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.","publish_time":1733575948621,"maintainers":[{"name":"borewit","email":"borewit@xs4all.nl"}],"_cnpm_publish_time":1733575948621,"dist-tags":{"latest":"0.6.0"}}