npm install @buh/unzip
Use inflateSync
from Bun.inflateSync
.
import { Zip } from '@buh/unzip';
const file = Bun.file('archive.zip');
const arrayBuffer = await file.arrayBuffer();
const zip = await Zip.create(arrayBuffer);
for (const entry of zip.iterator()) {
console.log(entry.fileName, entry.lastModified(), entry.getData());
}
Use inflateRawSync
from node:zlib
.
import { Zip } from '@buh/unzip';
import { readFileSync } from 'node:fs';
const file = readFileSync('archive.zip');
const zip = await Zip.create(file.buffer);
for (const entry of zip.iterator()) {
console.log(entry.fileName, entry.lastModified(), entry.getData());
}
I pretend to do my own inflate implementation for study purpose, but I recommend use pako
. Install npm install pako
.
import { Zip } from '@buh/unzip';
import { inflateRaw } from 'pako';
document.addEventListener('DOMContentLoaded', () => {
const input = document.querySelector('input[type=file]');
if (!input) return;
input.addEventListener('change', async () => {
const file = input.files[0];
const arrayBuffer = await file.arrayBuffer();
const zip = await Zip.create(arrayBuffer, { inflate: inflateRaw });
for (const entry of zip.iterator()) {
console.log(entry.fileName, entry.lastModified(), entry.getData());
}
});
});
You can track the changelogs in CHANGELOGS.md file.