I work with large text files in php (1GB +), I use
file_get_contents("file.txt", NULL, NULL, 100000000,100);
To get data from the middle of the file, but if I wanted to change the data in the file to something that is different from the original data, I would have to overwrite the entire file.
How can I change the data in a file (variable length) without overwriting the data if the data is larger than the original? I save the index of various data blocks in a file and their bytes. It seems that the only alternative is to allocate x number of bytes for each piece of data, and then rewrite this block if I want to change it ... the problem is that this will require a lot more space than zero bytes are needed , and it will take longer to write ... and it still wonโt decide how to โdeleteโ the data, since the file will never be reduced in size ... I really need help here ...
If I used prefix blocks for each piece of data in the file, for example 1 mb, then I wanted to enter data that was only 100kb , this record will take 10x the actual required space, and the record can never be changed to anything more than 1 mb of data, since it would rewrite more than the 1st allocated block ... deletion would be impossible ... I hope this makes sense ... I'm not looking for an alternative, I'm looking to write and change the data in the middle of the files heh ...
UPDATE: Yes, I would like to replace the old data, but if the new data is larger than the old data, I would like the rest of the data to be transferred further to the file ...
consider this: 0000000HELLODATA00000000 zeros represent empty space, nothing ... now I would like to replace HELLO SOMETHING, now that something is more than hi, just the entry at the start point of the greeting will expand by greeting and start overwriting the data .. therefore I would like DATA to be placed further in a file to make room for SOMETHING without overwriting DATA ... hehe