Skip to content

Commit 009a9be

Browse files
fix: Add abort signal (#162)
* Add abort signal * Run prettier:fix
1 parent f020216 commit 009a9be

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

PdfReader.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ PdfReader.prototype.parseFileItems = function (pdfFilePath, itemHandler) {
6060
});
6161
var verbosity = this.options.debug ? 1 : 0;
6262
pdfParser.loadPDF(pdfFilePath, verbosity);
63+
64+
this.options.signal?.addEventListener("abort", function () {
65+
pdfParser.destroy();
66+
});
6367
};
6468

6569
/**
@@ -80,4 +84,8 @@ PdfReader.prototype.parseBuffer = function (pdfBuffer, itemHandler) {
8084
});
8185
var verbosity = this.options.debug ? 1 : 0;
8286
pdfParser.parseBuffer(pdfBuffer, verbosity);
87+
88+
this.options.signal?.addEventListener("abort", function () {
89+
pdfParser.destroy();
90+
});
8391
};

index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
export type InitOptions = { password?: string; debug?: boolean };
1+
export type InitOptions = {
2+
password?: string;
3+
debug?: boolean;
4+
signal?: AbortSignal;
5+
};
26
export type Error = null | string;
37

48
export type DataEntry = {

0 commit comments

Comments
 (0)