Read binary file, encode it as base64 data and put this in json.
Display base64 in console.log (data.src) of readBinary function.
However, there is no src member in the resData JSON after calling the function.
How can I solve this?
What I have tried:
app.post('/server', function(req, res){
var resData = {};
resData = prevInstance[num].getFile(num++);
readBinary(resData, num);
console.log(resData);
res.json(redData);
});
function readBinary(data, file_id){
var fs = require('fs');
var bkgndBuffer = new Buffer.alloc(data.size, 'base64');
fs.open('projectfile.file', 'r', function(err, fd){
fs.read(fd, bkgndBuffer, 0, size, position, function(){
data.src=bkgndBuffer.toString('base64');
console.log(data.src);
});
fs.close(fd, function(){
console.log("exit file read.");
});
});
}