Skip to content

Commit

Permalink
Fix to prevent crash chunyenHuang#61
Browse files Browse the repository at this point in the history
The problem was that putting appendPage opens up a reader file resource that does not get released after function is complete, so when it is called within a large loop, the program runs out of file descriptors.
  • Loading branch information
shaehn committed Dec 17, 2019
1 parent 1c2a0ee commit a6262fa
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/appendPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ exports.appendPage = function appendPage(pdfSrc, pages = []) {
if (!Array.isArray(pages) && !isNaN(pages)) {
pages = [pages];
}
const pdfReader = hummus.createReader(pdfSrc);
// Using stream so it can be closed to release reader resource (Issue #61)
const instream = new hummus.PDFRStreamForFile(pdfSrc);
const pdfReader = hummus.createReader(instream);
const pageCount = pdfReader.getPagesCount();
instream.close();

// prevent unmatched pagenumber
const transformPageNumber = (pageNum) => {
pageNum = (pageNum > pageCount) ? pageCount : pageNum;
Expand Down

0 comments on commit a6262fa

Please sign in to comment.