{"id":28560659,"url":"https://github.com/borewit/tokenizer-inflate","last_synced_at":"2026-01-20T17:28:47.652Z","repository":{"id":264487744,"uuid":"893507714","full_name":"Borewit/tokenizer-inflate","owner":"Borewit","description":"A package designed for handling and extracting data from ZIP files efficiently using a tokenizer-based approach. The library provides a customizable way to parse ZIP archives and extract compressed data while minimizing memory usage.","archived":false,"fork":false,"pushed_at":"2025-06-08T13:35:15.000Z","size":1181,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-08T14:25:50.832Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Borewit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"Borewit","buy_me_a_coffee":"borewit"}},"created_at":"2024-11-24T16:16:02.000Z","updated_at":"2025-06-08T13:35:19.000Z","dependencies_parsed_at":"2024-12-02T09:58:21.682Z","dependency_job_id":"36ffc83c-fb9c-4ad0-9187-25040bbe540c","html_url":"https://github.com/Borewit/tokenizer-inflate","commit_stats":null,"previous_names":["borewit/tokenizer-deflate","borewit/tokenizer-inflate"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Borewit%2Ftokenizer-inflate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Borewit%2Ftokenizer-inflate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Borewit%2Ftokenizer-inflate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Borewit%2Ftokenizer-inflate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Borewit","download_url":"https://codeload.github.com/Borewit/tokenizer-inflate/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Borewit%2Ftokenizer-inflate/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259049812,"owners_count":22798032,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-10T09:37:31.769Z","updated_at":"2026-01-20T17:28:47.618Z","avatar_url":"https://github.com/Borewit.png","language":"TypeScript","funding_links":["https://github.com/sponsors/Borewit","https://buymeacoffee.com/borewit"],"categories":[],"sub_categories":[],"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\u0026interval=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) =\u003e {\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) =\u003e {\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\u003cboolean\u003e`\n\n   Determines whether the input file is a ZIP archive.\n\n- `unzip(fileCb: InflateFileFilter): Promise\u003cvoid\u003e`\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) =\u003e 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) =\u003e Promise\u003cvoid\u003e;\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.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborewit%2Ftokenizer-inflate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fborewit%2Ftokenizer-inflate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborewit%2Ftokenizer-inflate/lists"}