From 045d54e2e62f14c3658ab246c760f8c4da28b303 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Wed, 28 Feb 2024 13:15:47 +0000 Subject: [PATCH] Docs: include use of fetch() in Stream-based example --- docs/api-constructor.md | 10 ++++++---- lib/constructor.js | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/docs/api-constructor.md b/docs/api-constructor.md index 8f670e9cd..18ca29b1b 100644 --- a/docs/api-constructor.md +++ b/docs/api-constructor.md @@ -79,14 +79,16 @@ sharp('input.jpg') ``` **Example** ```js -// Read image data from readableStream, +// Read image data from remote URL, // resize to 300 pixels wide, // emit an 'info' event with calculated dimensions // and finally write image data to writableStream -var transformer = sharp() +const { body } = fetch('https://...'); +const readableStream = Readable.fromWeb(body); +const transformer = sharp() .resize(300) - .on('info', function(info) { - console.log('Image height is ' + info.height); + .on('info', ({ height }) => { + console.log(`Image height is ${height}`); }); readableStream.pipe(transformer).pipe(writableStream); ``` diff --git a/lib/constructor.js b/lib/constructor.js index 7f4e80da0..19c14a48c 100644 --- a/lib/constructor.js +++ b/lib/constructor.js @@ -40,14 +40,16 @@ const debuglog = util.debuglog('sharp'); * }); * * @example - * // Read image data from readableStream, + * // Read image data from remote URL, * // resize to 300 pixels wide, * // emit an 'info' event with calculated dimensions * // and finally write image data to writableStream - * var transformer = sharp() + * const { body } = fetch('https://...'); + * const readableStream = Readable.fromWeb(body); + * const transformer = sharp() * .resize(300) - * .on('info', function(info) { - * console.log('Image height is ' + info.height); + * .on('info', ({ height }) => { + * console.log(`Image height is ${height}`); * }); * readableStream.pipe(transformer).pipe(writableStream); *