https://github.com/tomashubelbauer/node-extract-zip
A pure Node function for extracting single-file ZIP archives
https://github.com/tomashubelbauer/node-extract-zip
deflate esm node zip
Last synced: about 1 month ago
JSON representation
A pure Node function for extracting single-file ZIP archives
- Host: GitHub
- URL: https://github.com/tomashubelbauer/node-extract-zip
- Owner: TomasHubelbauer
- Created: 2022-10-13T19:36:33.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-13T20:10:58.000Z (over 3 years ago)
- Last Synced: 2025-06-01T16:40:30.734Z (about 1 year ago)
- Topics: deflate, esm, node, zip
- Language: JavaScript
- Homepage: https://tomashubelbauer.github.io/node-extract-zip/index.js
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Node Extract Single-File ZIP Archive
[](https://github.com/TomasHubelbauer/node-extract-zip/actions/workflows/pages/pages-build-deployment)
The following snippet of code implements a function which will take a `Buffer`
of a ZIP archive file contents and find a single deflated file inside, which it
will then inflate and return the result as another `Buffer`.
It works by first looking for the EOCD (end of central directory) entry, from it
identifying the corresponding CD (central directory) entry and from it the data
size and offset of the DEFLATE stream.
The stream is then fed into `zlib` Node built-in module's function `inflateRaw`.
The implementation can be found in [`index.js`](index.js) or referenced via ESM
HTTP imports if you use the experimental `--experimental-network-imports` CLI
flag.
```javascript
import extract from 'https://tomashubelbauer.github.io/node-extract-zip/index.js';
const buffer = await extract(await fs.promises.readFile('archive.zip'));
const text = buffer.toString();
const data = JSON.parse(buffer);
```
This repository has an associated GitHub Pages site.
This is so that `index.js` can be accessed with a correct MIME type to be usable
with ESM.
The badge at the top relates to the GitHub Actions workflow for GitHub Pages.