0

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.

EDIT: I do not know if this will help but I am on Node v6.9.3

Sizzlor ox
  • 13
  • 3
  • might not be your problem, but `new Buffer()` is deprecated. Try to use either `data.toString()` directly (it's a buffer anyway), or `Buffer.from(data)` – ccprog Jun 03 '17 at 13:33
  • I downloaded node v6.9.3 and it seems to work fine. How are u calling the function ? – William Valhakis Jun 03 '17 at 13:38

0 Answers0