Closed lslzl3000 closed 1 year ago
Indeed, the demos only rely on Web APIs. I would recommend to use the Readable.toWeb()
/Writable.toWeb()
in order to convert Node.js streams into Web streams. Here is an example of code below.
import { ZipWriter, TextReader } from "@zip.js/zip.js";
import { open } from "node:fs/promises";
import { Writable } from "node:stream";
const TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.";
const FILENAME = "lorem.txt";
await test();
async function test() {
const filehandle = await open("./test.zip", "w");
const writeStream = filehandle.createWriteStream();
const zipWriter = new ZipWriter(Writable.toWeb(writeStream));
await zipWriter.add(FILENAME, new TextReader(TEXT_CONTENT));
await zipWriter.close();
}
I'm moving this issue into the discussions tab to keep it visible to people.
It seems that all demos were working with browsers Any example for nodejs? especially for the fs.stream