fflate
fflate copied to clipboard
`add()` for `ZipSync`
JSZip has a short and clear example.
I think it would convenient if this lib supports this approach from the box:
const zip = new fflate.ZipSync();
zip.add({
filename: "image.png",
data: imgData, // `ArrayBuffer`/`TypedArray`
});
zip.add({
filename: "docs/text.txt",
data: "The example text" // `String`, just use `new TextEncoder().encode(data)` in this case
mtime: new Date("2022-12-22 12:15:00")
});
/** @type {Uint8Array} */
const zipBytes = zip.end();
Optionally, the same approach for async version:
const zip = new fflate.Zip();
await zip.add({
filename: "image.png",
data: imgBlob, // additionally `Blob`/`File` support?
});
const resp = await fetch("https://example.com");
void zip.add({
filename: "sites/example.com.html",
data: resp.body // `ReadableStream`
});
const zipBytes = await zip.end();
fflate
's philosophy is to avoid validating or checking input and to not allow shorthands except where it yields no impact on bundle size, so this is not going to be implemented.
However, I am currently working on ezzip
, an fflate
wrapper with convenience features like these and modern APIs. I will take this feature request into consideration there and update here once it's published.
Also a wrapper for zipping a directory with a few lines of codes would be useful for Node.js.
Something like this:
const zip = new fflate.ZipSync();
zip.add({path: "./dir"});
zip.write("./result.zip");