From b202f827620735e97055dc4f0cb012372e8d70e4 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Wed, 23 Aug 2017 11:46:18 +0100 Subject: [PATCH] createToStream without promise streams are already async, and don't need to be wrapped in a promise. --- src/index.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/index.ts b/src/index.ts index eebfa7f6..8695bd8d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ import { launch, LaunchedChrome } from 'chrome-launcher'; import * as CDP from 'chrome-remote-interface'; +import { Readable, Stream } from 'stream'; import { ChromePrintOptions } from './ChromePrintOptions'; import * as CompletionTrigger from './CompletionTrigger'; @@ -50,6 +51,20 @@ export async function create(html: string, options?: CreateOptions): Promise { + try { + const result = await create(html, options); + stream.push(result.toBase64(), 'base64'); + stream.push(null); + } catch (e) { + stream.emit('error', e); + } + })(); + return stream; +} + /** * Connects to Chrome and generates a PDF from HTML or a URL. *