I’m writing an Ogg Vorbis Tagger for my application. Should be fairly easy, but there’s one conceptual problem I am in front of:
Since the Comment Header (the datablock that contains the Ogg Vorbis tags) will vary in size after tags have been added or removed, one will need to move the data that comes after the Comment Header from a former position X to a new position Y so it comes directly after the new Comment Header.
What’s the best way of doing this? 2 possibilities come to my mind:
(Can consume 100’s of MB of RAM if file is big): Read the entire file into memory, move data from X to Y, copy new Comment Header into memory, and finally write everything back to disk.
Read beginning of input file, append new Comment Header, put everything into an output file, and append the rest of the data after input file’s Comment Header to the output file. After that delete input file and rename output file to input file.
All this seems a little bit DIY to me, and maybe there’s a much simpler way of doing this “in place” (like in a Memory Mapped File) with JUCE, but I can’t figure out at the moment, so if anybody has some suggestions, please let me know. Thanks.