I want to create my own filetype in python that is a combination of a text file and an image file. I have an application in Python that I am working on that generates images with a bunch of associated data and I would like a way to save them together, which is why I want to create my own extension.
Specifically, I would like to have a file type that has the data for an image (.png or .jpg) and then store data in the form of a text file.
Like so
imageWithData.pngtxt -> {image.png +
data.txt.}
Other than using pickle to serialize the two objects (which I don't want to do for this situation), I'm not quite sure where to start or if this is possible and I'm not finding too much help on the web. Thanks!
You could write the length of the .png data stream to the file first (in bytes probably), then the .png data, then the .txt data. That way, when you read, you check the length of the .png data, then read that many bytes, and anything after that is .txt data. The way that you write the .png data is up to you - you could probably just write the binary data or a hexdump or something.
For example:
16
a7m<~:fU8vvy\`$@
The rest of the file is text data. The above is 16 random bytes
May I ask why you are opposed to a serializer, though?