Skip to content

Instantly share code, notes, and snippets.

@bonnak
Created December 30, 2019 07:17
Show Gist options
  • Select an option

  • Save bonnak/305fe2fc7846352767331257bd13d5b8 to your computer and use it in GitHub Desktop.

Select an option

Save bonnak/305fe2fc7846352767331257bd13d5b8 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