I am looking to create a file by structuring it in size blocks. Essentially I am looking to create a rudimentary file system.
I need to write a header, and then an “infinite” possible number of entries of the same size/structure. The important parts are:
- Each block of data needs to be read/writable individually
- Header needs to be readable/writable as its own entity
- Need a way to store this data and be able to determine its location in the file quickly
The would imagine the file would resemble something like:
[HEADER][DATA1][DATA2][DATA3][...]
What is the proper way to handle something like this? Lets say I want to read DATA3 from the file, how do I know where that data chunk starts?
If I understand you correctly and you need a way to assign a kind of names/IDs to your
DATAchunks, you can try to introduce yet another type of chunk.Let’s call it
TOC(table of contents).So, the file structure will look like
[HEADER][TOC1][DATA1][DATA2][DATA3][TOC2][...].TOCchunk will contain names/IDs and references to multipleDATAchunks. Also, it will contain some internal data such as pointer to the nextTOCchunk (so, you might consider eachTOCchunk as a linked-list node).At runtime all
TOCchunks could be represented as a kind ofHashMap, where key is a name/ID of theDATAchunk and value is its location in the file.