I ran into the problem of getting binary code from disk using the API, I keep working in circles.
Here are the relevant bits of code:
// Load client secrets from a local file. fs.readFile('client_secret.json', function processClientSecrets(err, content) { if (err) { console.log('Error loading client secret file: ' + err); return; } // Authorize a client with the loaded credentials, then call the // Drive API. oauth.authorize(JSON.parse(content), dasm.init, driveapi.getFile) });
driveapi.getFile:
function getFile(auth, cb) { var service = google.drive('v3'); service.files.get({ auth: auth, pageSize: 20, fileId: "0B2h-dgPh8_5CZE9WZVM4a3BxV00", alt: 'media' }, function(err, response) { if (err) { console.log('The API returned an error: ' + err); return; } cb(response) }); }
Now response appears as a string. When I try to convert to hex, it goes crazy. Is there a way to take response and get it in Buffer ? Or is it damaged when I get it from service.files.get ?
By nuts, I mean that
console.log( arrData[0].charCodeAt(0).toString(2), '-', arrData[1].charCodeAt(0).toString(2), '-', arrData[2].charCodeAt(0).toString(2), '-', arrData[3].charCodeAt(0).toString(2), '-', arrData[4].charCodeAt(0).toString(2) )
= 1001101 - 1011010 - 1111111111111101 - 0 - 11 (I use binary code to try to see what is broken)
The correct hex will be 4D 5A 90 00 03
Edit: for those who are embarrassed, like me, 90 become the fffd displayable Unicode replacement character when the value is not displayed on an ASCII char.