dart-lang / mime

Dart package for working with MIME type definitions and for processing streams of MIME multipart media types.
https://pub.dev/packages/mime
BSD 3-Clause "New" or "Revised" License
129 stars 51 forks source link

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

Open wrsilva opened 2 months ago

wrsilva commented 2 months ago

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 commented 1 month ago

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 commented 1 month ago

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