Skip to content

Commit

Permalink
createToStream without promise
Browse files Browse the repository at this point in the history
streams are already async, and don't need to be wrapped in a promise.
  • Loading branch information
graingert committed Aug 23, 2017
1 parent 4a4f21c commit b202f82
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -50,6 +51,20 @@ export async function create(html: string, options?: CreateOptions): Promise<Cre
}
}

function createToStream(html: string, options?: CreateOptions): Stream {
const stream = new Readable();
(async () => {
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.
*
Expand Down

0 comments on commit b202f82

Please sign in to comment.