Skip to content

Instantly share code, notes, and snippets.

@bartt
Created November 7, 2010 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bartt/667031 to your computer and use it in GitHub Desktop.
Save bartt/667031 to your computer and use it in GitHub Desktop.
var fs = require('fs');
// Start with a binary file
fs.readFile('foo.jpg', function(err, data){
// Write as base64 encoded text
fs.writeFile('foo.txt', data.toString('base64'), function(err){
// Read the base64 encoded file back in.
fs.readFile('foo.txt', function(err, data){
// Write back out as binary data
fs.writeFile('bar.jpg', data, 'base64', function(err){
// Yet bar.jpg === foo.txt instead of bar.jpg === foo.jpg
})
})
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment