Created
November 7, 2010 22:37
-
-
Save bartt/667031 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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