Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedded File is still being accessed by createReadStream asynchronously even after deletion in officegen for Word Document #408

Open
DilipSingh06 opened this issue Jun 12, 2023 · 0 comments

Comments

@DilipSingh06
Copy link

Environment

  1. node -v: 18.16.0
  2. npm -v: 9.5.1
  3. Operating system: Windows 10
  4. Microsoft Office version: 2016
  5. 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

        if (officegenGlobals.settings.verbose) {
          console.log('[officegen] Removing resource: ', filename)
        }

        fs.unlinkSync(filename)
      }
    })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant