neilharvey / FileSignatures

A small library for detecting the type of a file based on header signature (also known as magic number).
MIT License
250 stars 41 forks source link

Alternative extensions for formats (jpg, jpeg, ...) #60

Open drozdik-m opened 10 months ago

drozdik-m commented 10 months ago

Unfortunately, to my current understanding, some file extensions such as jpeg/jpg or tiff/tif have various alternative extensions. I need to validate that the file extension matches the mime type, but it is rather difficult, since this library does not take into consideration this alternative extension stuff.

Or, is it more complex than I think?

drozdik-m commented 10 months ago

There is even a conflict in README and code

image

image

neilharvey commented 10 months ago

Yes, currently only a single extension is supported. I don't like to make breaking changes but it is incorrect so perhaps I should change it.

I would be tempted to keep the existing property so we don't break anyone's code but mark it as obsolete (for the duration of a major version) so we would have something like:

public IEnumerable<string> Extensions { get; }

[Obsolete("Use Extensions property instead")]
public string Extension { get; } => Extensions.First();

Would that solve your issue?

drozdik-m commented 10 months ago

Yes, that sounds phenomenal, thank you.