-
Notifications
You must be signed in to change notification settings - Fork 12
feat: Make format optional for Reader to allow native lib to guess format #251
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
Changes from all commits
d74149b
ceccd6f
3b54169
6a52f30
eaaab9e
b447d52
0f15807
3e96662
e28b945
0349217
ece071b
b8af244
f7f0244
0c2324b
71b42ee
c812ef0
ab1efde
c901ba0
1ac9d8f
a7560df
a123fc3
0a97981
c14e106
5856400
3f5914f
8330a1f
015ed9b
3af00d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -741,7 +741,7 @@ namespace c2pa | |||||
| class C2PA_CPP_API Reader | ||||||
| { | ||||||
| private: | ||||||
| C2paReader *c2pa_reader; | ||||||
| C2paReader *c2pa_reader = nullptr; | ||||||
| std::unique_ptr<std::ifstream> owned_stream; // Owns file stream when created from path | ||||||
| std::unique_ptr<CppIStream> cpp_stream; // Wraps stream for C API; destroyed before owned_stream | ||||||
| std::shared_ptr<IContextProvider> context_ref; | ||||||
|
|
@@ -795,17 +795,37 @@ namespace c2pa | |||||
| /// @details The Reader retains a shared reference to the context, keeping it | ||||||
| /// alive for the lifetime of the Reader. | ||||||
| /// @param context Shared context provider. | ||||||
| /// @param format The mime format of the stream. | ||||||
| /// @param stream The input stream to read from. | ||||||
| /// @throws C2paException if context is null or context->is_valid() returns false. | ||||||
| /// @param format The mime type or file extension of the stream. Treated as a hint and | ||||||
| /// reconciled against the container detected in the leading bytes: the same | ||||||
| /// container keeps @p format (so "dng" is not widened to "image/tiff"), a | ||||||
| /// 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 | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||
| /// before inspection. | ||||||
| /// @throws C2paException if context is null or context->is_valid() returns false, or if | ||||||
| /// no container is detected and @p format does not name a supported one. | ||||||
| Reader(std::shared_ptr<IContextProvider> context, const std::string &format, std::istream &stream); | ||||||
|
|
||||||
| /// @brief Create a Reader from a shared context and stream, guessing the format from content. | ||||||
| /// @details Equivalent to passing an empty format. Detection is best effort; prefer the | ||||||
| /// 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. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||
| /// @throws C2paException if context is null, context->is_valid() returns false, or the | ||||||
| /// container type cannot be determined from the bytes. | ||||||
| Reader(std::shared_ptr<IContextProvider> context, std::istream &stream); | ||||||
|
|
||||||
| /// @brief Create a Reader from a shared context and file path. | ||||||
| /// @details The Reader retains a shared reference to the context, keeping it | ||||||
| /// alive for the lifetime of the Reader. | ||||||
| /// @param context Shared context provider. | ||||||
| /// @param source_path The path to the file to read. | ||||||
| /// @throws C2paException if context is null or context->is_valid() returns false. | ||||||
| /// @note The extension is used as a hint only. With no extension, the container is | ||||||
| /// guessed from the leading bytes (best-effort). A wrong or unrecognized | ||||||
| /// extension is accepted, since a detected container overrides it. | ||||||
| Reader(std::shared_ptr<IContextProvider> context, const std::filesystem::path &source_path); | ||||||
|
|
||||||
| /// @brief Create a Reader from a shared context, image stream, and external JUMBF manifest. | ||||||
|
|
@@ -877,10 +897,24 @@ namespace c2pa | |||||
|
|
||||||
| /// @brief Try to create a Reader from a shared context and stream when the asset may lack C2PA data. | ||||||
| /// @details The Reader retains a shared reference to the context if C2PA data is found. | ||||||
| /// @param context Shared context provider. | ||||||
| /// @param format The mime type or file extension of the stream, used as a hint and | ||||||
| /// reconciled against the detected container. See the corresponding constructor. | ||||||
| /// @param stream The input stream to read from. Must support seeking. | ||||||
| /// @return A Reader if JUMBF (c2pa/manifest) data is present; std::nullopt if none. | ||||||
| /// @throws C2paException for errors other than a missing manifest. | ||||||
| static std::optional<Reader> from_asset(std::shared_ptr<IContextProvider> context, const std::string &format, std::istream &stream); | ||||||
|
|
||||||
| /// @brief Try to create a Reader from a shared context and stream, guessing the format from content. | ||||||
| /// @details The Reader retains a shared reference to the context if C2PA data is found. | ||||||
| /// Detection is best effort; prefer the overload taking a format when it is known. | ||||||
| /// @param context Shared context provider. | ||||||
| /// @param stream The input stream to read from. Must support seeking. | ||||||
| /// @return A Reader if JUMBF (c2pa/manifest) data is present; std::nullopt if none. | ||||||
| /// @throws C2paException for errors other than a missing manifest. Content whose | ||||||
| /// container cannot be identified raises an error rather than returning nullopt. | ||||||
| static std::optional<Reader> from_asset(std::shared_ptr<IContextProvider> context, std::istream &stream); | ||||||
|
|
||||||
| // Non-copyable | ||||||
| Reader(const Reader&) = delete; | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍