Skip to content

Commit d88fba8

Browse files
committed
Enable new buffer to create recipe
Fixes #372
1 parent 0c5ca21 commit d88fba8

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

lib/Recipe.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ class Recipe {
2828
this.src = src;
2929
// detect the src is Buffer or not
3030
this.isBufferSrc = this.src instanceof Buffer;
31-
this.isNewPDF = !this.isBufferSrc && src.toLowerCase() === "new";
31+
this.isNewPDF =
32+
(!this.isBufferSrc && src.toLowerCase() === "new") ||
33+
(this.isBufferSrc && this.src.equals(Buffer.from("new")));
3234
this.encryptOptions = this._getEncryptOptions(options, this.isNewPDF);
3335
this.options = Object.assign({}, options, this.encryptOptions);
3436
this.current = {};
@@ -75,12 +77,21 @@ class Recipe {
7577

7678
_createWriter() {
7779
if (this.isNewPDF) {
78-
this.writer = muhammara.createWriter(
79-
this.output,
80-
Object.assign({}, this.encryptOptions, {
81-
version: this._getVersion(this.options.version),
82-
}),
83-
);
80+
if (!this.isBufferSrc) {
81+
this.writer = muhammara.createWriter(
82+
this.output,
83+
Object.assign({}, this.encryptOptions, {
84+
version: this._getVersion(this.options.version),
85+
}),
86+
);
87+
} else {
88+
this.writer = muhammara.createWriter(
89+
new muhammara.PDFStreamForResponse(this.outStream),
90+
Object.assign({}, this.encryptOptions, {
91+
log: this.logFile,
92+
}),
93+
);
94+
}
8495
} else {
8596
this.read();
8697
try {

0 commit comments

Comments
 (0)