-
Notifications
You must be signed in to change notification settings - Fork 31k
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
add path.mimeType()
and path.charset()
to node:path
#54595
Comments
path.mimeType()
and path.charset()
to node:path
For
For |
Personally, I'm -1 on adding this to core. Mimetypes can be easily done in userland using a Charsets require reading the file, which is not something the path module does, and I don't think it is something the path module should. |
@jasnell It is not clear to me that it is necessary to look at the contents of the file. The chatset can be extracted from the mimeType, and the mimeType from the file extension. Nowadays the libraries that support this make use of this JSON reference: https://github.com/jshttp/mime-db/blob/master/db.json
@redyetidev as I commented the current libraries to do this extract the And about the mapping, yes, can be done via a |
(CC @nodejs/path) (While I am not a core collaborator) I still strongly disagree with the addition of this API into the core of Node.js. While I do greatly appreciate this issue being opened, I have some major concerns with this API. Here are a few of them: 1. MaintainabilityIf Node.js were to implement this feature, the project would need to take on the significant responsibility of maintaining a constantly evolving and extensive map from file extensions to character sets and MIME types. Additionally, the project would have to handle edge cases, conflicts, and potential ambiguities that may arise due to overlapping file extensions or varying interpretations of MIME type specifications across different platforms and software. 2. Redundancy with Existing EcosystemThe Node.js ecosystem already includes well-established modules like 3. Performance ConcernsImplementing and maintaining a reliable MIME type and charset detection mechanism within the Node.js core could introduce performance overhead, particularly in cases where the detection process is complex or requires frequent updates to a large mapping table. Even if the performance impact is minimal, the added complexity in the core could have unintended side effects on the overall performance of the Node.js runtime. |
There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the
never-stale
|
By the way, if it helps in the future when this conversation comes up again, mime-db doesn't strictly follow semver since the records can change (see jshttp/mime-db#331, jshttp/mime-db#330) and break certain applications. Just my two cents, but even though other runtimes have it implemented, I don't think Node.js should implement it. |
What is the problem this feature will solve?
Adding
path.mimeType()
andpath.charset
will solve the dependency on an external library, mime-types, to get the content type of a file based on its extension. This can be done with Node.js itself, just as Bun.js does withBun.file(file).type
.What is the feature you are proposing to solve the problem?
I am proposing to add two new methods to the path module:
mimeType
- returns the MIME type of a file based on its extension.charset
- returns the charset of a MIME type.And:
What alternatives have you considered?
Alternatively, instead of being in
node:path
, it could be infs.stat
, but I think that in the end it can be extracted from the path without having to parse the file, besides it is better to use functions for this and the work is done only if they are executed individually.CC: @vdeturckheim
The text was updated successfully, but these errors were encountered: