Class DataCompressor
Thin GZip wrapper used by SaveData to reduce the on-disk and in-memory footprint of serialised JSON save files.
public sealed class DataCompressor
Inheritance
Remarks
JSON produced by JsonUtility.ToJson is highly repetitive ASCII text — field names and
structural characters repeat across every record — so GZip typically achieves a 60–70 %
size reduction on study save files. This matters for WebGL deployments where browser
storage quotas are measured in megabytes and a single long session can accumulate hundreds
of actor-state snapshots.
GZip was chosen over Deflate or Brotli because .NET's built-in
GZipStream requires no additional packages, handles
both streaming and in-memory byte arrays, and is readable by standard tooling for
post-hoc inspection of save files.
All methods are static because the class carries no instance state; sealed prevents
subclassing a utility type that has no virtual members.
Methods
Compress(byte[])
Compresses rawData using GZip and returns the compressed bytes.
public static byte[] Compress(byte[] rawData)
Parameters
| Name | Type | Description |
|---|---|---|
rawData | byte[] | The raw, uncompressed data to be compressed. |
Returns
byte[] — A byte array containing the GZip-compressed form of rawData.
Remarks
The compressed bytes are written to a MemoryStream rather than a
file, so the caller can pass them to a FileStream or cache them
in memory without an intermediate file-system write.
Decompress(byte[])
Decompresses a GZip-compressed byte array and returns the original uncompressed bytes.
public static byte[] Decompress(byte[] compressedData)
Parameters
| Name | Type | Description |
|---|---|---|
compressedData | byte[] | The GZip-compressed data to decompress. |
Returns
byte[] — A byte array containing the original, uncompressed data.
Remarks
Mirrors Byte[]): reads from a MemoryStream wrapping
the input and copies the decompressed output into a second in-memory stream, avoiding any
temporary file-system writes.