Conversation
|
This is just a WIP as I'm not sure what the interface should be. |
src/index.ts
Outdated
| } | ||
| } | ||
|
|
||
| function generateToStream(html: string, options: CreateOptions): Stream { |
There was a problem hiding this comment.
I think await generate(...).then(v => v.toStream()) should be deprecated.
|
Here's example usage: const pdf = await htmlPdf.create(html, options);
const stream = pdf.toStream(); // Look mom, no Promises!The only async toFile(filename: string): Promise<void> |
|
@westy92 code should be: const stream = htmlPdf.createToStream(html, options); // Look parent, no Promises! |
|
@westy92 because |
streams are already async, and don't need to be wrapped in a promise.
f93fa7f to
b202f82
Compare
Codecov Report
@@ Coverage Diff @@
## master #43 +/- ##
==========================================
- Coverage 100% 93.22% -6.78%
==========================================
Files 3 3
Lines 108 118 +10
Branches 12 12
==========================================
+ Hits 108 110 +2
- Misses 0 8 +8
Continue to review full report at Codecov.
|
|
@westy92 obviously I'll update the tests if you agree with this interface. |
|
I'm not sure what's with the Can you provide a use case for needing this functionality? |
|
@westy92 I don't have Promise phobia, I just don't want them in the stream interface where they're unused. |
|
@westy92 eg it would match the node API for createReadStream: https://nodejs.org/api/fs.html#fs_fs_createreadstream_path_options |
|
Your implementation is just hiding the |
|
@westy92 sure it's hiding the promise, that's what streams are for. |
|
@westy92 if you were to add an Observable interface, eg when they land natively in node, it would look very strange to do: Observable.from(htmlPdf.create(html, options)).flatMap(v => v.toObservable());vs: htmlPdf.createObservable(html, options);Which is analogous to the current stream API. |
|
It appears that https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF now has a That should allow us to implement this fairly simply. |

streams are already async, and don't need to be wrapped in a promise.