using System; using K4os.Compression.LZ4; namespace SongCore.Arcache { // idx: [[len:2] [u8str:len] [offset:8] [compressedSize:8] [originalSize:8]] ... // dat: [block] ... public abstract class Lz4ArchiveBase { public static byte[] Compress(byte[] source) { var target = new byte[LZ4Codec.MaximumOutputSize(source.Length)]; var len = LZ4Codec.Encode(source, target, LZ4Level.L12_MAX); var compressed = new byte[len]; Buffer.BlockCopy(target, 0, compressed, 0, len); return compressed; } public static byte[] Decompress(byte[] source, int originalSize) { var decompressed = new byte[originalSize]; LZ4Codec.Decode(source, decompressed); return decompressed; } public static byte[] CompressPickle(byte[] source) { return LZ4Pickler.Pickle(source,LZ4Level.L12_MAX); } public static byte[] DecompressPickle(byte[] source) { return LZ4Pickler.Unpickle(source); } protected internal string BlobFilePath; protected internal string IndexFilePath; protected internal Lz4ArchiveBase(string pathAndBaseName) { BlobFilePath = pathAndBaseName + ".lz4a"; IndexFilePath = pathAndBaseName + ".lz4i"; } } }