-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetIt.js
28 lines (24 loc) · 1.03 KB
/
getIt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var fs = require('fs');
// function to encode file data to base64 encoded string
function base64_encode(file) {
// read binary data
var bitmap = fs.readFileSync(file);
// convert binary data to base64 encoded string
return new Buffer(bitmap).toString('base64');
}
// function to create file from base64 encoded string
function base64_decode(base64str, file) {
// create buffer object from base64 encoded string, it is important to tell the constructor that the string is base64 encoded
var bitmap = new Buffer(base64str, 'base64');
// write buffer to file
fs.writeFileSync(file, bitmap);
console.log('******** File created from base64 encoded string ********');
}
// convert image to base64 encoded string
//var base64str = base64_encode('kitten.jpg');
//console.log(base64str);
// convert base64 string back to image
var bitmap = fs.readFileSync('node-v6.7.0-x64.b64');
// convert binary data to base64 encoded string
var base64str = new Buffer(bitmap).toString();
base64_decode(base64str, 'node-v6.7.0-x64.msi');