-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Low level MIME sniffing #49843
Comments
Both have problems. Just looking at the extension is prone to false positives (e.g. GIF file with a .jpg extension), while sniffing the first few bytes is problematic with non-files like fifos (can't seek, can't rewind.) Even determining if a file is text/plain is challenging if you don't know the encoding. A file consisting of the octets https://mimesniff.spec.whatwg.org/ seems to be aimed at HTTP, not file systems, so I don't think it's of much use. I feel node shouldn't be in the business of making educated guesses, not when everyone else is making different educated guesses. |
For future reference, we have a fast mimesniff parser at Ada - https://github.com/ada-url/mimesniff |
A million years ago i programmed this Is this something we should put in a transform stream? |
There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the
never-stale
|
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment. For more information on how the project manages feature requests, please consult the feature request management document. |
What is the problem this feature will solve?
This issue came up during a discussion related to
fs.openAsBlob
, whereblob.type
currently returns an empty string. I must agree that it would be nice if Node.js could automatically determine the MIME type of a given entity, whether through extension lookup or by inspecting "magic numbers".Of course, there might be some cases where certain file extensions collide, but I believe it would be best to adhere to the IANA standards. After all, all browsers are capable of deducing certain information. Here's a straightforward example:
I'm not sure about the exact mechanism behind it, but it simply works somehow.
I've come across some useful resources that might help address this issue:
These resources could provide valuable insights and potential solutions for improving the MIME type detection in Node.js.
What is the feature you are proposing to solve the problem?
I'm unsure about the API's potential appearance, but it would be beneficial to explore various methods for detecting it. I'm also uncertain whether it should return an array of potential matches along with their respective scores and probabilities.
For instance:
Perhaps when searching for a path, it could consider both the file name extension and perform MIME sniffing.
Lastly:
Please note that the exact method names and functionality would depend on the implementation details of the API.
I think this would serve the community to have this built right in as it's something that is very commonly used.
The text was updated successfully, but these errors were encountered: