From 4e90b87d826adee4e67a14a016b986f2c35e8134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Am=C3=A9rico?= Date: Fri, 21 Dec 2018 20:33:14 -0300 Subject: [PATCH] Remove setTimeout call in PDFReference.finalize --- lib/reference.js | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/lib/reference.js b/lib/reference.js index 067fcb3ce..f5b7dd116 100644 --- a/lib/reference.js +++ b/lib/reference.js @@ -42,39 +42,36 @@ class PDFReference extends PDFAbstractReference { } finalize() { - return setTimeout(() => { - this.offset = this.document._offset; + this.offset = this.document._offset; - const encryptFn = this.document._security ? this.document._security.getEncryptFn(this.id, this.gen) : null; + const encryptFn = this.document._security ? this.document._security.getEncryptFn(this.id, this.gen) : null; - if (this.buffer.length) { - this.buffer = Buffer.concat(this.buffer); - if (this.compress) { - this.buffer = zlib.deflateSync(this.buffer); - } - - if (encryptFn) { - this.buffer = encryptFn(this.buffer); - } + if (this.buffer.length) { + this.buffer = Buffer.concat(this.buffer); + if (this.compress) { + this.buffer = zlib.deflateSync(this.buffer); + } - this.data.Length = this.buffer.length; + if (encryptFn) { + this.buffer = encryptFn(this.buffer); } - this.document._write(`${this.id} ${this.gen} obj`); - this.document._write(PDFObject.convert(this.data, encryptFn)); + this.data.Length = this.buffer.length; + } - if (this.buffer.length) { - this.document._write('stream'); - this.document._write(this.buffer); + this.document._write(`${this.id} ${this.gen} obj`); + this.document._write(PDFObject.convert(this.data, encryptFn)); - this.buffer = []; // free up memory - this.document._write('\nendstream'); - } + if (this.buffer.length) { + this.document._write('stream'); + this.document._write(this.buffer); - this.document._write('endobj'); - return this.document._refEnd(this); + this.buffer = []; // free up memory + this.document._write('\nendstream'); } - , 0); + + this.document._write('endobj'); + this.document._refEnd(this); } toString() { return `${this.id} ${this.gen} R`;