-
Notifications
You must be signed in to change notification settings - Fork 8
feat: Adds support for Reader to_folder method #31
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -465,6 +465,33 @@ pub unsafe extern "C" fn c2pa_reader_resource_to_stream( | |
} | ||
} | ||
|
||
/// Writes all the resources in a Reader to a folder. | ||
/// | ||
/// # Parameters | ||
/// * reader_ptr: pointer to a Reader. | ||
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. I like to add if the memory pointed to is actually modified or used read-only. |
||
/// * folder_path: pointer to a C string with the path to the folder. | ||
/// | ||
/// # Errors | ||
/// Returns -1 if there were errors, otherwise returns 0. | ||
/// The error string can be retrieved by calling c2pa_error. | ||
#[no_mangle] | ||
pub unsafe extern "C" fn c2pa_reader_to_folder( | ||
reader_ptr: *mut C2paReader, | ||
folder_path: *const c_char, | ||
) -> c_int { | ||
let c2pa_reader: Box<C2paReader> = Box::from_raw(reader_ptr); | ||
let folder_path = from_cstr_null_check_int!(folder_path); | ||
let result = c2pa_reader.to_folder(folder_path); | ||
let _ = Box::into_raw(c2pa_reader); | ||
match result { | ||
Ok(_) => 0, | ||
Err(err) => { | ||
Error::from_c2pa_error(err).set_last(); | ||
-1 | ||
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. Not saying we should, but we could return more precise error codes in the future (not for this PR). |
||
} | ||
} | ||
} | ||
|
||
/// Creates a C2paBuilder from a JSON manifest definition string. | ||
/// | ||
/// # Errors | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,7 +104,7 @@ TEST(Builder, SignStream) | |
dest.seekp(0, std::ios::beg); | ||
auto reader = c2pa::Reader("image/jpeg", dest); | ||
auto json = reader.json(); | ||
ASSERT_TRUE(json.find("c2pa.training-mining") != std::string::npos); | ||
ASSERT_TRUE(json.find("cawg.training-mining") != std::string::npos); | ||
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. Ack - |
||
} | ||
catch (c2pa::Exception const &e) | ||
{ | ||
|
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.
Your non-native reviewer got confused by the wording, but maybe my grammer is off.