2

I have a Node.js service that creates a PDF file for download using pdfmake. It works perfectly, but I need to find a way to guarantee the intergrity of the generated file, so that any changes in that file could make it invalid.

I do not save the file into the filesystem, but send it directly to the client's browser using pdfDoc.pipe(res):

module.exports = async function (res) {
   ...
   var pdfDoc = printer.createPdfKitDocument(docDefinition);
   pdfDoc.pipe(res);
   pdfDoc.end();
}

How can I generate the hash for that file without writing it to the disk? How to check the integrity later on?

I have tried to send the content to a variable so that I could calculate the SHA256 hash, but had no success. After researching thoroughly on that, I still have no clue on how to do it.

0 Answers0