Skip to content

Instantly share code, notes, and snippets.

@Rotron
Created March 28, 2019 15:24
Show Gist options
  • Save Rotron/eb2fdac7cb9a2f1c6437692c5ead4556 to your computer and use it in GitHub Desktop.
Save Rotron/eb2fdac7cb9a2f1c6437692c5ead4556 to your computer and use it in GitHub Desktop.
Write buffer to file nodejs
var crypto = require('crypto');
var fs = require('fs');
var wstream = fs.createWriteStream('myBinaryFile');
// creates random Buffer of 100 bytes
var buffer = crypto.randomBytes(100);
wstream.write(buffer);
// create another Buffer of 100 bytes and write
wstream.write(crypto.randomBytes(100));
wstream.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment