Hi Exhydra,
I like some of your concepts in your script
Woo, it's Zeriab!
I suggest you use Zlib::Deflate.deflate and Zlib::Inflate.inflate for compression as that will allow you to do in memory decompression.
I also suggest that you add the decompression logic to the load_data method as that is the only way to load marshalled objects from the encrypted archive.
Originally, I tried using Deflate and Inflate, but I kept getting errors about how I couldn't compress an Array/Hash into a String (which is what Deflate and Inflate try and do; turn the input into a string to compress). I dug around in the Ruby docs to try and find a way around what was going on, but I could never find it. I got frustrated and decided to dump the Gzipped files to the hard drive for a moment to un-compress and load them instead of doing it in memory like I wanted.
Here is my very alpha code when I was trying to load compressed files into memory. It's really sloppy, but I remember Deflate giving me errors about how it couldn't convert the Array to a String :
def compress_data #(filename)
buf_nrm = nil
buf_zlb = nil
buf_str = ""
buf_nrm = load_data('Data\Actors.rvdata')
buf_zlb = Zlib::Deflate.deflate(buf_nrm)
save_data(buf_zlb, 'Data\Actors.gzdata')
end
def decompress_data(data_stream)
buf = []
buf = Zlib::Inflate.inflate(data_stream)
return buf
end
Right now I'm already using 'load_data' to take the marshalled files from the encrypted archive. Unless I'm not understanding what you're suggesting. I tried to find the code for the 'load_data' method, as putting decompression code in there would increase compatibility, but I couldn't find it.
To get around the problems I was having, I put a Marshall 'wrapper' around the GZipped file. This is pretty inefficient, but it works. So right now the script is operating kind of like this :
< Compression (Done before Encrypted Archive is created) >
Buffer << File (Local Drive)
Deflate >> File (Local Drive)
Save_Data >> File (Local Drive)
-> File Structure [ Marshall > GZip > Marshall ]
< Decompression >
Buffer << Load Data | Encrypted Archive
Buffer >> File (Local Drive)
Inflate >> File (Local Drive)
Buffer << Load_Data | Marshalled File
<< Delete File
Note that the compression ratios will most likely not be as big in practice. I did an experiment where I compressed the rxdata for 5 commercial RMXP projects and found that difference was smaller than what the test data indicated, but very much significant if you looked at the data folders alone. On the downside was that the reducing in total project size was only 3-4% which is still better than nothing.
Yeah, I know that typically the Data directory really isn't that large. I was just thinking that it would work nicely on some bigger projects (50+ maps) or projects that use sizable maps (not that there are many who do that), it would be more of a boon. But to the normal RPG Maker user, it probably won't squeeze a whole lot out ... but every little bit helps, I guess!
EDIT: By the way, I put your old
Remove Comments project in the
Project Optimization thread I've been slowly building. It works really nicely.