felixc / rexiv2

Rust library for read/write access to media-file metadata (Exif, XMP, and IPTC)
GNU General Public License v3.0
79 stars 17 forks source link

Expose raw bytes for in-memory operations #35

Closed brownjohnf closed 5 years ago

brownjohnf commented 5 years ago

Hey, I'm trying to calculate the checksum of an image after calling clear (https://felixcrux.com/files/doc/rexiv2/struct.Metadata.html#method.clear). I want to get a checksum that won't change even if tags have been added/removed/changed. I'd like to get the raw bytes of the image back after making the change so I don't have to call save_to_file (https://felixcrux.com/files/doc/rexiv2/struct.Metadata.html#method.save_to_file). It looks like there's a raw field on the Metadata struct, but it's private.

Would it be possible to add a method to return the contents of the image as a Vec or something similar (I'm pretty new to rust; not sure what would be ideal). Alternatively, am I just thinking about this problem incorrectly? I'm open to other/better solutions. Thanks!

brownjohnf commented 5 years ago

I guess I should add that I'd be happy to take this on, if it's something that sounds good, but I wanted to make sure that I'm understanding the situation correctly.

felixc commented 5 years ago

Hey @brownjohnf — I think I get what you're after, and it makes sense to me! The tricky bit may be that the raw field is actually just a pointer to one of these: https://gnome.pages.gitlab.gnome.org/gexiv2/docs/GExiv2Metadata.html and I'm not sure if there is anything that gives direct access to the image bytes (with or without metadata).

Possibly you could hack something with https://gnome.pages.gitlab.gnome.org/gexiv2/docs/GExiv2Metadata.html#gexiv2-metadata-save-stream by building up the Vec with data from the callbacks you supply? I'm not sure if it that would work or if there's a better way but it's where I would start looking...

brownjohnf commented 5 years ago

Hm, okay. I wound up using https://crates.io/crates/image to solve the problem on my end, but I'm curious if I could make this work (and learn some more rust). Then I'd have one fewer dependency, as well.

I'm not sure when I'll have time, but I'll give this a look. Should I leave this open, or close it for now?

felixc commented 5 years ago

I'd gladly incorporate a PR with this functionality if you were to create one, but I'm not likely to pick this up otherwise... so perhaps the issue should be closed unless you'd like somewhere to discuss the problem further?

felixc commented 5 years ago

Closing for now but would be happy to reopen to discuss further if you do end up finding the time to make a PR! Cheers!