Page MenuHomePhabricator

Extend custom mime type by functions to get filename and extension
Closed, ResolvedPublic

Description

Currently the AppliesTo method of the custom mime checks whether any of the supported extensions is found at the end of the given path. It only returns whether this is true or not, leaving the individual readers/writers to duplicate the code to get the matching extension and the filename without the extension.

Ideally this could be centralized in the custom mime type with the following functions:

string GetExtension( string path )

Which returns the matching extension (e.g. "nii.gz" for the file "/eve/foo.bar.nii.gz")

string GetFilename( string path )

which returns the filename minus the extension and directories (e.g. "foo.bar" for the file "/eve/foo.bar.nii.gz")

These functions as well as the existing AppliesTo function should share a helper function which provides all the relevant values, thus avoiding code duplication.

The suggested solution will always return the extension/filename as fits the *first* matching extension for a given mime type. Theoretically a mime type could contain several matching extensions (e.g. in the above case ".nii.gz" and ".bar.nii.gz") this is however unlikely and will not be handled unless a use case presents itself.

Event Timeline

User goch has pushed new remote branch:

bug-18653-extend-custom-mime-type

In addition to the mentioned functions there was a fix in the Core Activator where a nifti mime type for the readers was constructed with only the name, but missing extensions.

[371731]: Merge branch 'bug-18653-extend-custom-mime-type'

Merged commits:

2015-01-21 18:03:57 Caspar Goch [aa1879]
Correctly initialize mime types


2015-01-21 17:56:22 Caspar Goch [89bfeb]
Correctly initialize mime types


2015-01-21 17:01:33 Caspar Goch [fea84f]
Provide functions to get filename and extension


2015-01-21 16:59:34 Caspar Goch [976484]
Use entire Nifti mime type

Previously a new empty mime type was generated containing only the nifti
mime type name