Skip to content

Commit

Permalink
Docs: include use of fetch() in Stream-based example
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Feb 28, 2024
1 parent 75fedf1 commit 045d54e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions docs/api-constructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
```
Expand Down
10 changes: 6 additions & 4 deletions lib/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
*
Expand Down

0 comments on commit 045d54e

Please sign in to comment.