julianhille / MuhammaraJS

Muhammara a node module with c/cpp bindings to modify PDF with js for node or electron (based/replacement on/of galkhana/hummusjs)
Other
229 stars 46 forks source link

Not able to close reader while deleting the file #325

Closed manjilkhambe closed 1 year ago

manjilkhambe commented 1 year ago

Hi, I am reading PDF from physical path using createReader('/some/path'); I am using then reader to file information and creating xobjects from it and copying it in another file using createWriter. Now I want to delete the file but unable to do so, it gives file busy error. Is there a way to release the reader file? like close method in Muhammara.PDFRStreamForFile ?

julianhille commented 1 year ago

Normally you would just call close on the reader. Mind adding more code?

manjilkhambe commented 1 year ago

Apologies. I should have been more concise. Please refer the code below -

image

After writer.end(), I want to delete the both files - readerPath & destination. I am able to delete the destination file which is given to writer but the readerPath file, it gives me File busy error. The thing is Muhammara.PDFRStreamForFile has close() method which solves the problem but I don't want to use that. Is there anything which can solve this problem.

julianhille commented 1 year ago

you could go this way:

const instream = new muhammara.PDFRStreamForFile(readerPath);
  const reader = muhammara.createReader(instream);
  .....

  instream.close();
  // delete here
julianhille commented 1 year ago

did this solve your problem?

manjilkhambe commented 1 year ago

Yes, this could solve the problem.