harshankur / officeParser

A Node.js library to parse text out of any office file. Currently supports docx, pptx, xlsx and odt, odp, ods..
MIT License
150 stars 20 forks source link

Using the current time to form a temp file name can lead to errors when multiple files are being processed in parallel #20

Closed gsbelarus closed 1 year ago

gsbelarus commented 1 year ago

Replace current time with UUID:

const newfilepath = `${internalConfig.tempFilesLocation}/tempfiles/${new Date().getTime().toString()}.${data.ext.toLowerCase()}`;
harshankur commented 1 year ago

@gsbelarus Thank you for pointing this out.

My interest in using the timestamp is not just for it to be unique. Rather, it has also to do with the temp files being sorted in chronological order as how they appear in a list, usually in an IDE. However, I do understand your point that if there are multiple calls made in an async way, they might all be processed at the same time essentially leading to files overlapping and that is not good.

So, I believe the best way to tackle this and preserve the chronological order is by having a global iterator for files that we increment the iterator and append to the file name after the timestamp, thereby preserving the chronological order.