Saturday, 3 June 2017

node readFile wont fire callback

So I am trying read a PDF file and send its buffer as an attachment to an email. The strange thing is I have never had the problem with fs.readFile before, the callback just never fires. I have tried checking the pdf if I can open it, if anything is corrupt but it seems fine.

const destination = './temp/somthing.pdf'

function encodeToBase64(destination, callback) {
  return fs.readFile(destination, function (err, data) {
    if (err) {
      return callback(err);
    }
    return callback(null, new Buffer(data).toString('base64'));
  });
}

I use VSCode and have added breakpoints on all the returns and the node debugger is able to reach the first return which is the readFile, but once I go to the next step my CPU starts to work like a boss and the VSCode node debugger shows messages saying node is unresponsive.

I am at a total loss here as to what is going on. I have tried multiple pdf files aswell but to no avail.



via Sizzlor ox

No comments:

Post a Comment