Akira
Akira copied to clipboard
Reduce saved file size
We currently save our files in a JSON
format which lists all the items and their properties.
We also save the imported images in a dedicated folder to always have the original available even if the user resizes it or reduces the quality on the canvas.
Everything is packed together into a .akira
file, which is actually a .zip
file.
I'm looking for ways to reduce the file size without losing quality.
JSON content
@esodan suggested to convert the JSON
file into a binary representation of GLib.Variant
.
That sounds like a good idea, but I have no idea how to do it and, so I'm totally open to suggestions and contributions.
Image size
We want to keep the originally imported image inside the saved file, but I'd like to find a way to reduce the file size in case the user imports many large images into its project. Is there some sort of conversion, or non destructive compression that can be reverted on loading? The images are automatically deleted from the saved file if the user removes every instance of those from the canvas, so there's no problem from that point of view.
From GVls support of Meson files, you can read a string an convert to GLib.Variant
using this:
Json.Parser parser = new Json.Parser ();
parser.load_from_data (str);
Json.Node node = parser.get_root ();
GLib.Variant v = Json.gvariant_deserialize (node, null);
commands.parse_variant (v);
Above code takes a JSON formated code an convert to GLib.Variant
using Json.gvariant_deserialize
, the inverse process is using Json.gvariant_serialize.
GVls has GVls.VariantObject, a non invasive interface that when implemented add a parse_variant
and to_variant
methods, so any GLib.Object
class is scanned for properties to serialize/deserialize; all its properties are converted to equivalente JSON data types. An example on how GVls use it to read a JSON file then automatically fills out a GLib.Object
can be found at GVls.MesonCommands. If you need a list of GVls.VariantObject
objects of the same type (like strings or other GVls.VariantObject
derived types), GVls uses GVls.Container
that implement GLib.ListModel
so you can use to add objects to, then you can serialize to/from GLib.Variant
objects.
GLib.Variant,store helps to store a serialized binary version of Variant, the contrary form is use get_data
or GLib.Variant.get_normal_form
my knowledge in programming is very very very basic. but maybe it will help:
@Alecaddd for the pictures maybe you can use JPEG-XL. it can compress JPEG images without losing quality.
and maybe if we will use 7z technology instead of zip it can reduce file size too.