A while back I wrote a module called Archive::Tyd, which is for *simplistic* archiving of multiple files. Currently how it works is:
The Tyd archive has a format like this for storing all of its files (when in unencrypted form):
With one file on its own line. End-of-line characters are substituted and can be rechanged later when the file needs to be accessed.
When all the file data is combined in this format, the resulting scalar is encrypted using Crypt::CipherSaber using a password provided by the program running the module.
How it currently works is that the entire archive is loaded into memory, so that $tydobj->{files}->{'filename'} has the data to that file. This works when the archive is full of small files that can easily fit into memory.
I was thinking of ways to allow Tyd to hold larger files but without draining memory to do so. I was thinking that the first line in the unencrypted file could be an index listing what lines each file exists on.
But the problem still would arrise when one of those lines is to be read from, or when the module is going to write all of the files back into the archive again.
The question is: is it possible to make a filehandle from a set of internal data, so that large files can be read by their filehandle instead of slurping all of their data at once?
So in this case, if the data for "movie.mpeg" existed on line 6 of the archive, and my program wanted to access this file (maybe to write it directly to an external file)... how could I turn its data into a filehandle, so that a while(<FH>) could be used on it?
The Tyd archive has a format like this for storing all of its files (when in unencrypted form):
Code:
filename::data
filename::data
filename::data
...
With one file on its own line. End-of-line characters are substituted and can be rechanged later when the file needs to be accessed.
When all the file data is combined in this format, the resulting scalar is encrypted using Crypt::CipherSaber using a password provided by the program running the module.
How it currently works is that the entire archive is loaded into memory, so that $tydobj->{files}->{'filename'} has the data to that file. This works when the archive is full of small files that can easily fit into memory.
I was thinking of ways to allow Tyd to hold larger files but without draining memory to do so. I was thinking that the first line in the unencrypted file could be an index listing what lines each file exists on.
But the problem still would arrise when one of those lines is to be read from, or when the module is going to write all of the files back into the archive again.
The question is: is it possible to make a filehandle from a set of internal data, so that large files can be read by their filehandle instead of slurping all of their data at once?
So in this case, if the data for "movie.mpeg" existed on line 6 of the archive, and my program wanted to access this file (maybe to write it directly to an external file)... how could I turn its data into a filehandle, so that a while(<FH>) could be used on it?