Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.

Commit acef5e0

Browse files
authored
Merge pull request foliojs#887 from blikblum/remove-reference-timeout
Remove setTimeout call in PDFReference.finalize
2 parents 56d4327 + 4e90b87 commit acef5e0

1 file changed

Lines changed: 21 additions & 24 deletions

File tree

lib/reference.js

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,39 +42,36 @@ class PDFReference extends PDFAbstractReference {
4242
}
4343

4444
finalize() {
45-
return setTimeout(() => {
46-
this.offset = this.document._offset;
45+
this.offset = this.document._offset;
4746

48-
const encryptFn = this.document._security ? this.document._security.getEncryptFn(this.id, this.gen) : null;
47+
const encryptFn = this.document._security ? this.document._security.getEncryptFn(this.id, this.gen) : null;
4948

50-
if (this.buffer.length) {
51-
this.buffer = Buffer.concat(this.buffer);
52-
if (this.compress) {
53-
this.buffer = zlib.deflateSync(this.buffer);
54-
}
55-
56-
if (encryptFn) {
57-
this.buffer = encryptFn(this.buffer);
58-
}
49+
if (this.buffer.length) {
50+
this.buffer = Buffer.concat(this.buffer);
51+
if (this.compress) {
52+
this.buffer = zlib.deflateSync(this.buffer);
53+
}
5954

60-
this.data.Length = this.buffer.length;
55+
if (encryptFn) {
56+
this.buffer = encryptFn(this.buffer);
6157
}
6258

63-
this.document._write(`${this.id} ${this.gen} obj`);
64-
this.document._write(PDFObject.convert(this.data, encryptFn));
59+
this.data.Length = this.buffer.length;
60+
}
6561

66-
if (this.buffer.length) {
67-
this.document._write('stream');
68-
this.document._write(this.buffer);
62+
this.document._write(`${this.id} ${this.gen} obj`);
63+
this.document._write(PDFObject.convert(this.data, encryptFn));
6964

70-
this.buffer = []; // free up memory
71-
this.document._write('\nendstream');
72-
}
65+
if (this.buffer.length) {
66+
this.document._write('stream');
67+
this.document._write(this.buffer);
7368

74-
this.document._write('endobj');
75-
return this.document._refEnd(this);
69+
this.buffer = []; // free up memory
70+
this.document._write('\nendstream');
7671
}
77-
, 0);
72+
73+
this.document._write('endobj');
74+
this.document._refEnd(this);
7875
}
7976
toString() {
8077
return `${this.id} ${this.gen} R`;

0 commit comments

Comments
 (0)