writing-a-plugin "Call the callback function only when the current file (stream/buffer) is completely consumed"
See original GitHub issueWhat were you expecting to happen?
Following the verbal guidance here -
“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)
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?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:10 (3 by maintainers)
Top GitHub Comments
@craigphicks that’s just an empty transformFunction; I could have just left the function out completely, as I’m not actually doing any transformation; I’m really just using newStream as a passthrough so I can use it for newFile. More here: https://www.npmjs.com/package/through2#transformfunction
Thanks for the good word! Be aware that gulp-api-adapter is very much under construction; it’s being developed to work with our gulp-etl project, but hopefully it’ll have some utility in the wider gulp world.
Hopefully it’ll be usable and stable later this week…
Have you actually tried your code, and gotten another result? When I run my take of it (wrapping it in a function with cb as a parameter), I get the same behaviour as with my example: with
size()
,bogusname
is empty, without it, it is not.(I believe
stream.end()
indicate that no more data will be written to the stream, but it does not really affect the readable part of the stream. Maybe?)The point was that
gulp-size
also seems to be written with the understanding that the callback function should be called after the vinyl content’s stream has been processed. Like this:Where the function
finish
calls the callback function.I guess it could be possible to construct an even smaller example exposing the behaviour, using gulp-size as a starting point.