Standalone Office Open XML files (Microsoft Office 2007 and later) generator for Word (docx), PowerPoint (pptx) and Excell (xlsx) in javascript. The output is a stream.
MIT License
2.66k
stars
471
forks
source link
Embedded File is still being accessed by createReadStream asynchronously even after deletion in officegen for Word Document #408
Problem with Powerpoint, Excel or Word document: Word Document
Steps to Reproduce
Try to embed a excel file called sample.xlsx into word document. On adding a new resource I am passing "removed_after_used": true. This removes the temporary file once it is embedded in the document.
Once it is deleted in the code, still the createReadStream is trying to look for the file as the contents copying is still not finished. This is resulting into the below error
ENOENT: no such file or directory, open 'D:\sample1.xlsx
This stops the officegen to generate a docx file
[fill]
Expected Behavior
The file should be deleted only after the createReadStream has finished reading the file. It should be done on the finished event of createReadStream or the reading should be done synchronously using readFileSync
Actual Behavior
The file is still being accessed by createReadStream even after it has been deleted by officegen resulting in an error.
case 'file':
resStream = fs.readFileSync(
privateData.resources[cur_index].data ||
privateData.resources[cur_index].name
)
break
This is deleting the file after use but the above createReadStream is still accessing it.
privateData.resources.forEach(function (resource) {
if (resource.removed_after_used) {
var filename = resource.data || resource.name
Environment
node -v
: 18.16.0npm -v
: 9.5.1Steps to Reproduce
Try to embed a excel file called sample.xlsx into word document. On adding a new resource I am passing "removed_after_used": true. This removes the temporary file once it is embedded in the document.
Once it is deleted in the code, still the createReadStream is trying to look for the file as the contents copying is still not finished. This is resulting into the below error
ENOENT: no such file or directory, open 'D:\sample1.xlsx
This stops the officegen to generate a docx file [fill]
Expected Behavior
The file should be deleted only after the createReadStream has finished reading the file. It should be done on the finished event of createReadStream or the reading should be done synchronously using readFileSync
Actual Behavior
The file is still being accessed by createReadStream even after it has been deleted by officegen resulting in an error.
case 'file': resStream = fs.readFileSync( privateData.resources[cur_index].data || privateData.resources[cur_index].name ) break
This is deleting the file after use but the above createReadStream is still accessing it. privateData.resources.forEach(function (resource) { if (resource.removed_after_used) { var filename = resource.data || resource.name