Refine README example (#463)
This reverts commit fa6548ed31
(#441).
The autoClose option has been true by default since at least Node.js
v6.0.0. There is no need to set it once more.
Instead, make the example more realistic by handling stream outcomes
using a promise.
See #375.
This commit is contained in:
parent
5bc23d81cf
commit
2b7e1ab27f
15
README.md
15
README.md
|
@ -80,10 +80,19 @@ fetch('http://domain.invalid/')
|
||||||
|
|
||||||
fetch('https://assets-cdn.github.com/images/modules/logos_page/Octocat.png')
|
fetch('https://assets-cdn.github.com/images/modules/logos_page/Octocat.png')
|
||||||
.then(res => {
|
.then(res => {
|
||||||
const dest = fs.createWriteStream('./octocat.png', {
|
return new Promise((resolve, reject) => {
|
||||||
autoClose: true,
|
const dest = fs.createWriteStream('./octocat.png');
|
||||||
|
res.body.pipe(dest);
|
||||||
|
res.body.on('error', err => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
dest.on('finish', () => {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
dest.on('error', err => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
res.body.pipe(dest);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// buffer
|
// buffer
|
||||||
|
|
Loading…
Reference in New Issue