Abort stream after first chunk
- Dominant language
- JavaScript
- Stars
- 12.1k
- Forks
- 1.1k
- Avg merge
- 8d 2h
- Merged PRs (30d)
- 21
Description
Many files have a distinct pattern in the first few byte, so called [magic number](https://en.wikipedia.org/wiki/Magic_number_%28programming%29). There could be a use case to peek at the numbers before deciding wether to accept the file or not.
I don't really know how the api would look for this to be implemented in a really clean and clear way.
Basically what we want to do is to capture `data` events until we have at least `n` bytes. Then the stream should be paused and the bytes should then be passed to some kind of user defined function that works out if it's allowed or not. If it's allowed, these bytes would then be written to the destination stream, and then the paused stream should be piped to the destination and then resumed.
I'm not sure that the benefit of this outweighs the cost of maintaining it, but if we can come up with a good api I would be open to merge that.
Contributor guide
Assessment
This issue has not been assessed yet.