node-archiver icon indicating copy to clipboard operation
node-archiver copied to clipboard

Can I get the Buffer from fs.createWriteStream()?

Open sergey-prosvirnin opened this issue 6 years ago • 1 comments

I have simple question - Can I get the Buffer from fs.createWriteStream()?

In my case I use archiver NPM module wich may create archives from Buffer. When this module end work with method archive.finalize() I may get result from archive.pipe(stream). I want have Buffer from fs.createWriteStream() wich I may send to res.send() Express method.

let archive = archiver("zip", {
      zlib: { level: 9 } // Sets the compression level.
    });
const stream = fs.createWriteStream(
      "./src/backend/api/test.zip"
    );
archive.pipe(stream);
archive.append(buffer, { name: "test.csv" });
archive.finalize();

Thank for you answer! And sorry for realy bad English.

sergey-prosvirnin avatar Oct 11 '19 07:10 sergey-prosvirnin

Hello there, not an expert but here is what I did

const fs = require("fs");

// the rest of the code

res.send(fs.readFileSync(zipPath))

james-muriithi avatar Jun 27 '23 08:06 james-muriithi