Skip to content

[MIME] Expand default extension map #2027

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 3 commits into from
Closed

[MIME] Expand default extension map #2027

wants to merge 3 commits into from

Conversation

NickNevzorov
Copy link

I am using packages, that depends on mime (for example, DropTarget). I need to add my file extension to default map, but it is Const

I propose change to Final, now my code is:

import 'package:mime/mime.dart' as mime;
mime.defaultExtensionMap['wxo'] = 'application/wxo';

This will give the opportunity to add own extension types in standard resolver

@lrhn
Copy link
Member

lrhn commented Mar 5, 2025

I don't think a global mutable shared map is a good idea. Anyone can add anything to it, but they can also delete from it.

I'd rather do something more local, like a zone based override of the map.

@NickNevzorov
Copy link
Author

I don't think a global mutable shared map is a good idea. Anyone can add anything to it, but they can also delete from it.

I'd rather do something more local, like a zone based override of the map.

I am using drop_terget, witch using mime. In my code:

if (file.mimeType == "application/wxo") ...

How can I add my custom file type to mime package ?

No i write:

if (file.name.contains('.wxo'))

But is looking not good

@lrhn
Copy link
Member

lrhn commented Mar 5, 2025

I don't definitely agree that it's not looking as good. Maybe it's on princple.

Doing mime.defaultExtensionMap['wxo'] = 'application/wxo'; and then recognizing that the file.mimeType being application/wxo is just doing the same thing with more steps.

It's getting some other code to do your extension(file) == 'wxo' for you, but it's the same test.

But if you are otherwise using mimeType to recognize things, I can see how it's easier to do everything the same way.

(Probably should use file.name.endsWith('.wxo') just to be safe.)

This package should get a policy/process for how to get mappings added to the map.
It's clearly possible (mappings have been added in the past).
But requests for adding mappings have also been open for a long time, so it's not automatic.
(So I agree something should be done, but this isn't it.)

@NickNevzorov NickNevzorov closed this by deleting the head repository Mar 17, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants