mardi 31 mars 2015

Node base64 encode doesn't give whole string

Good day,


I am having a weird issue with Node, I am encoding a file as Base64 and albeit it works for most of my PDFs that I am encoding, one in particular doesn't output the whole base64 string.


The actual b64 string starts like this: "JVBERi0xLjMKJf////8KNiAwIG9i..." but I only get "JVBERi0xLjMK"


Here is my code:



function sendPDF() {
// Grab the final PDF
require('fs').readFile(transaction.deliverable, function (err, data) {
if (err) {
console.log(err);
log(2, "Couldn't read: " + transaction.deliverable);
} else {
transaction.deliverable = new Buffer(data, 'binary').toString('base64');
//transaction.deliverable = data.toString('base64');
console.log(transaction.deliverable);

}


The commented out line was another attempt. The transaction structure is:



function Transaction(snapshot) {
var data = snapshot.val();
this.tid = snapshot.key();
this.request = data.request;
this.pages = [];
this.fileCount = 0;
this.deliverable = null;
this.fileName = "";
}


This transaction simple stores some information that I pull from Firebase however the important var, .deliverable is a string to the path of the PDF I need to encode and send.


I don't get any read errors when this happens, and the next transaction goes through this code block just fine, giving a full base64 string.


I was curious if my toString() was interpolating the base64 string, but then I thought I would have had larger problems earlier.


Any ideas? I can put this on hold and move on with my work but I would love to fix this.. Thank you.


Aucun commentaire:

Enregistrer un commentaire