I am currently working on manipulating the metadata in a format called EPS. At it's origins it's all text but because I save the files in a custom Adobe format they call EPS10 (which also allows the format to have metadata at all) there is a portion of it that is encoded as binary data.
What I am trying to do is separate the text from the binary without touching the latter. I've managed to do this in a small test project, on a txt file with special characters. I load the file into a BinaryData with Ajax, then I copy the binary into a string as text, solely for the purpose of figuring out where the binary data starts. Within the string I look for a certain phrase/tag that signals the begging of the binary stuff, which, thankfully, is all at the end of the file. In this case I choose an arbitrary point where I break the file in half. Now I have the ByteOffset by which I can copy the binary data from the BinaryData object into a new temporary BinaryData object, for safekeeping. Now I cut off the corrupted binary data from the text string and do my edits on the meta part of it. Now I rewrite the BinaryData object by loading the text string into it, aka the first half of the file and then I attach the actual binary data I was safekeeping, aka the second half of the file. Now the file is successfully altered without corrupting the binary information. And just to clarify, I indeed have no intention of altering that information, only to work around it without breaking it.
My main confusion was about how to use the data manipulation actions on the BinaryData object since I never worked with binary before. I think I got it to a degree. I am yet to implement this technique into my actual software but the test project seems to have worked because in the txt file it alters, the first half has it's special characters all screwed-up while the second part doesn't.
As for JPGs, I see that they keep all their metadata right at the beginning of the file so it would probably work the same.