Gzip compression doesnt work with Cache location

Discussion and help for Easy Save 3
Post Reply
zamaroth
Posts: 2
Joined: Fri Sep 23, 2022 12:08 pm

Gzip compression doesnt work with Cache location

Post by zamaroth »

Hello,

I found an issue, where compression doesnt work with cache.

I made the following example:

Code: Select all

var testObject = new GameObject("testObject");

// Normal

ES3Settings settingsCache = new ES3Settings() { location = ES3.Location.Cache };

ES3.DeleteFile(settingsCache);

ES3.Save("object", testObject, settingsCache);

var data = ES3.LoadRawBytes(settingsCache);

File.WriteAllBytes(Path.Combine(Application.dataPath, "normal.json"), data);


// Compressed file

ES3Settings settingsCompFile = new ES3Settings() { compressionType = ES3.CompressionType.Gzip, location = ES3.Location.File };

ES3.DeleteFile(settingsCompFile);

ES3.Save("object", testObject, settingsCompFile);

data = ES3.LoadRawBytes(settingsCompFile);

File.WriteAllBytes(Path.Combine(Application.dataPath, "compressed_file.json"), data);


// Compressed file fixed

ES3.DeleteFile(settingsCompFile);

ES3.Save("object", testObject, settingsCompFile);

data = ES3.LoadRawBytes(new ES3Settings(ES3.Location.File));

File.WriteAllBytes(Path.Combine(Application.dataPath, "compressed_file_fixed.json"), data);


// Compressed cache

ES3Settings settingsCompCache = new ES3Settings() { compressionType = ES3.CompressionType.Gzip, location = ES3.Location.Cache };

ES3.DeleteFile(settingsCompCache);

ES3.Save("object", testObject, settingsCompCache);

data = ES3.LoadRawBytes(new ES3Settings(ES3.Location.Cache));

File.WriteAllBytes(Path.Combine(Application.dataPath, "compressed_cache.json"), data);
These are the results if I run the example:
Results.zip
(1.67 KiB) Downloaded 62 times

First issue even with File location is that LoadRawBytes cannot have compression in its settings. If it has the compression wont work.
Second issue, when using compression and cache location together, compression wont work.

Only case when compression worked was when Save had (location=File, compression=Gzip) and LoadRawBytes had (location=File)
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Gzip compression doesnt work with Cache location

Post by Joel »

Hi there, and thanks for the detailed information.

Regarding your 'Compressed cache' sample: ES3.LoadRawBytes will return the current representation in memory of that data. As compression isn't applied to cached data until StoreCachedFile() is called, it won't return a compressed string. However, I'll change it so that compression is applied in the next update. If you private message me your invoice number I can send over the update right away.

Regarding 'Compressed file', this is expected behaviour. By enabling encryption you're telling Easy Save to run the data through the encryption engine. This means data is encrypted when saved, and decrypted when loaded. In this case you should disable the encryption engine if you don't want decryption to occur by specifying ES3.EncryptionType.None.

EDIT: Actually our unit tests show that this change will break code for those on older versions, so instead we will add ES3.Compress and ES3.Decompress methods.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply