Pdf file parsing working better after fs.write and fs.read, why?

Viewed 14

I got an array of objects containing pdf filenames and its buffer, which i got from scraping some webpages. I need to execute a parse function on them, but I´m getting errors frequently at the parser. I figured out the buffer could be saved to the file system just fine, so they should be ok, and then the parser could read them just fine too from the file system. Now, instead of executing the parser on the buffer, i tried to write and read the file and it works... I want to know why is that happening and how to avoid these read/write operations.

Not working:

let data = await myReader.parse(myPdf.buffer);

Working:

fs.writeFileSync(myPdf.name,myPdf.buffer);
let newBuffer = fs.readFileSync(myPdf.name);
let data = await myReader.parse(newBuffer);
0 Answers
Related