Created
October 6, 2016 14:48
-
-
Save thelbouffi/d3a1010edbc3bfd2d4b7f7898f795307 to your computer and use it in GitHub Desktop.
Coding and decoding a file in base64 (for example a pdf file)
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'); | |
// Reade file synchronously and put the result in buffer | |
var file = fs.readFileSync('fileName.pdf'); | |
// Code the file in base64 | |
var base64EncodedPDF = new Buffer(file).toString('base64'); | |
// Decode the file | |
var baseDecodedPDF = new Buffer(base64EncodedPDF, 'base64'); | |
// Get the decoded file in its original format | |
fs.writeFileSync('decodedPDF.pdf', baseDecodedPDF); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment