Build and read zip files with whatwg streams in the browser.
/ˈkänˌfləks/
(noun) a flowing together of two or more streams
- 21.6 kB import
- Uses streams, minimizing memory overhead
# With Yarn
yarn add @transcend-io/conflux
# With NPM
npm install --save @transcend-io/conflux
import Zip from "@transcend-io/conflux/write";
const { readable, writable } = new Zip();
import Zip from "@transcend-io/conflux/write";
import streamSaver from "streamsaver";
// Set up conflux
const { readable, writable } = new Zip();
const writer = writable.getWriter();
// Set up streamsaver
const fileStream = streamSaver.createWriteStream("conflux.zip");
// Add a file
writer.write({
name: "/cat.txt",
lastModified: new Date(0),
stream: () => new Response("mjau").body
});
readable.pipeTo(fileStream);
writer.close();
(async () => {
writer.write({
name: "/cat.txt",
lastModified: new Date(0),
stream: () => new Response("mjau").body
});
const imgStream = await fetch(
"https://s3-us-west-2.amazonaws.com/bencmbrook/Earth.jpg"
).then(r => r.body);
writer.write({
name: "/Earth.jpg",
lastModified: new Date(0),
stream: () => imgStream
});
readable.pipeTo(fileStream);
writer.close();
})();
import reader from "@transcend-io/conflux/read";
fetch("https://cdn.jsdelivr.net/gh/Stuk/jszip/test/ref/deflate.zip").then(
async res => {
const zip = await res.blob();
for await (const entry of reader(zip)) {
console.log(entry);
}
}
);