Skip to main content

CompressionUtilities

A class in Root.Township, the global namespace.

Editor tool plus static helpers that pack a file or folder into a gzip file with a simple custom layout, and unpack it. Not a standard zip or tar.

Constructors​

MemberWhat it is
CompressionUtilities()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

6 private and internal fields
MemberWhat it is
private string filePathFile or folder to zip from the inspector.
private bool isCompressingInspector button that zips filePath.
private bool isDecompressingInspector button that unzips targetToUnZip and deletes it after.
private string outputFileFolder the zip is written into.
private string targetToUnZipPacked file to unzip from the inspector.
private string unzippingFolderFolder to unzip into.

Methods​

MemberWhat it is
static string CompressFile(string fileToCompress, string destinationFolderPath)Public overload: packs a file or folder into name.gz in the destination folder and returns that path. The private ones write single entries.
static bool DecompressFile(string fileToDecompress, string folderToCompressTo, bool isDeletingCompressedFile)Public overload: unpacks a packed file into a folder and can delete the packed file. The private one reads one entry.
6 private and internal methods
MemberWhat it is
private static void CompressDirectory(string directoryPath, string compressedPath, CompressionUtilities.ProgressDelegate progress = null)Writes every file under a folder into one gzip stream, after a leading 1 byte that marks it as a folder.
private static void CompressFile(string filePath, string relativePath, string compressedPath)Public overload: packs a file or folder into name.gz in the destination folder and returns that path. The private ones write single entries.
private static void CompressFile(string filePath, string relativePath, GZipStream zipStream)Public overload: packs a file or folder into name.gz in the destination folder and returns that path. The private ones write single entries.
private static bool Decompress(string compressedFilePath, string outputFileName, string destinationPath, CompressionUtilities.ProgressDelegate progress = null)Reads the leading byte, then unpacks every entry (folder) or the single entry (file).
private static bool DecompressFile(string folderPath, GZipStream compressedStream, CompressionUtilities.ProgressDelegate progress = null)Public overload: unpacks a packed file into a folder and can delete the packed file. The private one reads one entry.
private void OnValidate()Runs zip or unzip when the matching inspector button is pressed.