Skip to content

Conversation

@ireun
Copy link

@ireun ireun commented May 27, 2025

High level overview:

  1. if a file is actually jpeg but with wrong extension:
    use native methods, display a warning
    EDIT: warn only with -v
  2. if a file is not actually a jpeg, and has a wrong extention:
    display an error, skip processing - exiftool will fail either way so don't waste time for that.

I might still refactor this, but I want you to take a look. :)

Additionally we need only 96 bytes for header MIME detection. (https://github.com/dart-lang/tools/blob/main/pkgs/mime/lib/src/magic_number.dart has at most 12 HEX values (each has 2 digits) for the header matching -> 12*2*4=96). I've used 128 just in case some future MIME types would require more.

@ireun
Copy link
Author

ireun commented May 27, 2025

Preview:
image

@ireun ireun marked this pull request as ready for review May 27, 2025 15:17
@ireun ireun changed the base branch from 4.0.2-development to v4.0.3-development May 28, 2025 18:42
Copy link
Owner

@Xentraxx Xentraxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I trust you researched the change to 128 bytes, so thats fine!
I'll look at the rest!

@Xentraxx
Copy link
Owner

Okay looks good and makes sense! Approved.

@Xentraxx Xentraxx merged commit 1b28f31 into Xentraxx:v4.0.3-development May 28, 2025
@ireun ireun deleted the 4.0.2-development branch May 28, 2025 23:20
@ireun
Copy link
Author

ireun commented May 28, 2025

Next thing to do would be to create a renaming mechanism based on mimeTypeFromHeader, then this whole PR could be removed from code base.

@ireun
Copy link
Author

ireun commented May 30, 2025

One issue I've found with this:

Some RAW formats (like Canon RAW) are based on TIFF formats. For real .CR2 mimeLookup(path) will return null, while mimeLookup(path, header) will return image/tiff.

I've made PR to add proper mimeLookup() for .CR2 - dart-lang/tools#2105.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants