Skip to content
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

.XLS | .XLSX | .CSV in lookupMimeType #428

Open
wrsilva opened this issue Apr 19, 2024 · 2 comments
Open

.XLS | .XLSX | .CSV in lookupMimeType #428

wrsilva opened this issue Apr 19, 2024 · 2 comments

Comments

@wrsilva
Copy link

wrsilva commented Apr 19, 2024

lookupMimeType is it possible to add support for extensions .XLS | .XLSX | .CSV ?

String mimeType = lookupMimeType('test', headerBytes: file.take(defaultMagicNumbersMaxLength).toList()) ?? '';

mimeType return null

@FitzM
Copy link

FitzM commented May 25, 2024

lookupMimeType is it possible to add support for extensions .XLS | .XLSX | .CSV ?

String mimeType = lookupMimeType('test', headerBytes: file.take(defaultMagicNumbersMaxLength).toList()) ?? '';

mimeType return null

What is returned from the file.take(defaultMagicNumbersMaxLength).toList()) ? I'm not sure where file is coming from. I don't think you're able to declare .take on a FileSystemEntity

@wrsilva
Copy link
Author

wrsilva commented May 29, 2024

lookupMimeType is it possible to add support for extensions .XLS | .XLSX | .CSV ?
String mimeType = lookupMimeType('test', headerBytes: file.take(defaultMagicNumbersMaxLength).toList()) ?? '';
mimeType return null

What is returned from the file.take(defaultMagicNumbersMaxLength).toList()) ? I'm not sure where file is coming from. I don't think you're able to declare .take on a FileSystemEntity

image

The take method is used to select only the first defaultMagicNumbersMaxLength bytes of the file, converting them into a list, which is then passed to the lookupMimeType function to identify the file's MIME type. This improves the efficiency of the code, ensuring that only the necessary amount of data is processed.

By limiting the reading to the first bytes using take, the code avoids unnecessary reading of the entire file, which can be costly in terms of performance, especially for large files.

in magic_number no contains xml or csv
https://github.com/dart-lang/mime/blob/b01c9a24e0991da479bd405138be3b3e403ff456/lib/src/magic_number.dart#L29

@mosuem mosuem transferred this issue from dart-archive/mime Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants