writing-a-plugin "Call the callback function only when the current file (stream/buffer) is completely consumed"
- Dominant language
- JavaScript
- Stars
- 32.9k
- Forks
- 4.1k
- PR merge metrics
- No merged PRs in 30d
Description
**What were you expecting to happen?**
Following the verbal guidance [here](https://github.com/gulpjs/gulp/tree/master/docs/writing-a-plugin) -
> "Call the callback function only when the current file (stream/buffer) is completely consumed"
then in case of `file.IsStream()` I expected to need to wait for the 'end' event from the inner transform before calling the `callback()`.
**What actually happened?**
As shown in the code example on that man page, it only works if `callback()` is called immediately.
**Please post a sample of your gulpfile (preferably reduced to just the bit that's not working)**
```js
innerTransform.on('end', () => {
cb(null, file) // gulp writes an empty file doing it this way
})
```
Actually implementing the above code (instead of calling the `callback` immediately), resulted in an empty file being written, although the inner transform had dutifully pushed all the data.
**What version of gulp are you using?**
gulp 4
**What versions of npm and node are you using?**
npm 6.9.0
gulp 4.0.2
-------------
I am unable to convince myself that
> when the current file (stream/buffer) is completely consumed
could mean anything other than the `end` event has been emitted. Furthermore, the wording seems perfect from a design point of view, and fits with all the usage of `callback`s that I know.
How to reconcile the words and the actual design?
Contributor guide
Assessment
This issue has not been assessed yet.