expressjs / expressjs/multer

Abort stream after first chunk

Open
#155 16 comments 12 reactions 0 assignees View on GitHub
enhancement future
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.