Skip to content

feat: Make format optional for Reader to allow native lib to guess format - #251

Merged
tmathern merged 28 commits into
mainfrom
mathern/guess-reader-type
Jul 29, 2026
Merged

feat: Make format optional for Reader to allow native lib to guess format#251
tmathern merged 28 commits into
mainfrom
mathern/guess-reader-type

Conversation

@tmathern

@tmathern tmathern commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Make format optional for Reader to allow native lib to guess format (+overloads for the Reader).

@tmathern tmathern self-assigned this Jul 27, 2026
@tmathern
tmathern marked this pull request as ready for review July 28, 2026 16:53
@tmathern
tmathern requested review from gpeacock and ok-nick July 28, 2026 17:33
Comment thread src/c2pa_context.cpp
Comment thread src/c2pa_internal.hpp

@gpeacock gpeacock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's a LOT of tests added. Was this all driven by the format detection stuff, or were we generally missing tests here? This seems like a lot to support at one binding level vs driving the logic and tests to the rust layer.

@tmathern

tmathern commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

That's a LOT of tests added. Was this all driven by the format detection stuff, or were we generally missing tests here? This seems like a lot to support at one binding level vs driving the logic and tests to the rust layer.

Yes, all the formats variations with blank strings, padding and the like. I also verified the behavior for builder and the embeddable APIs (making sure there are not surprises).

Update: I also ported some tests from Python that caused surprising errors there (looking at you, DNG). I have many ideas how to try to break this, so I added matching coverage...

I'm not against pulling things down in Rust, but that means also when we do C++ only, we're more blind/trusting of the Rust coverage (I do not necessarily run the Rust tests when I do C++ only). It makes me feel better to have the test coverage here too.

@tmathern
tmathern merged commit 0b121cc into main Jul 29, 2026
16 of 17 checks passed
@tmathern
tmathern deleted the mathern/guess-reader-type branch July 29, 2026 20:55

@ale-adobe ale-adobe left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I know already merged, but just had some comments that I didn't get to submit beforehand.

Comment thread include/c2pa.hpp
{
private:
C2paReader *c2pa_reader;
C2paReader *c2pa_reader = nullptr;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Comment thread include/c2pa.hpp
/// different one wins over @p format, and if nothing is detected @p format is
/// used as given. Pass an empty string to rely on detection alone. A format
/// absent from supported_mime_types() is not rejected here.
/// @param stream The input stream to read from. Must support seeking; it is rewound

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do we enforce the seeking requirement in any way, or do we just end up erroring and say it's the user's fault? If we throw an error, I think the comment below needs updating.

Comment thread include/c2pa.hpp
/// overload taking a format when the format is known.
/// The stream is rewound before inspection, so it must support seeking.
/// @param context Shared context provider.
/// @param stream The input stream to read from. Must support seeking.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit, for consistency. Also noticed this a few more times below.

Suggested change
/// @param stream The input stream to read from. Must support seeking.
/// @param stream The input stream to read from. Must support seeking; it is rewound before inspection.


/// Formats that count as absent: empty, or only ASCII whitespace.
inline const std::vector<std::string> kBlankFormats = {
"", " ", " ", "\t", "\n", "\t\n ", "\r\n", "\v\f"};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is the third string here three spaces? Why does that need its own entry?

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.

3 participants