using System; using System.Diagnostics; using System.Reflection.Emit; using System.Runtime.InteropServices; namespace LZ4Sharp { /// /// Static LZ4 Compression and Decompression. This is threadsafe because it creates new instances of the /// compression/decompression classes for each method call. /// It is recommended to use LZ4Compressor and LZ4Decompressor for repeated compressing/decompressing for speed and less memory allocations. /// public static unsafe class LZ4 { public static byte[] Compress(byte[] source) { return LZ4CompressorFactory.CreateNew().Compress(source); } /// /// Calculate the max compressed byte[] size given the size of the uncompressed byte[] /// /// Length of the uncompressed data /// The maximum required size in bytes of the compressed data public static int CalculateMaxCompressedLength(int uncompressedLength) { return LZ4CompressorFactory.CreateNew().CalculateMaxCompressedLength(uncompressedLength); } /// /// Compress source into dest returning compressed length /// /// uncompressed data /// array into which source will be compressed /// compressed length public static int Compress(byte[] source, byte[] dest) { return LZ4CompressorFactory.CreateNew().Compress(source, dest); } /// /// Compress source into dest returning compressed length /// /// uncompressed data /// offset in source array where reading will start /// count of bytes in source array to compress /// array into which source will be compressed /// start index in dest array where writing will start /// compressed length public static int Compress(byte[] source, int srcOffset, int count, byte[] dest, int dstOffset) { return LZ4CompressorFactory.CreateNew().Compress(source, srcOffset, count, dest, dstOffset); } public static void DecompressKnownSize(byte[] compressed, byte[] decompressed) { LZ4DecompressorFactory.CreateNew().DecompressKnownSize(compressed, decompressed); } public static int DecompressKnownSize(byte[] compressed, byte[] decompressedBuffer, int decompressedSize) { return LZ4DecompressorFactory.CreateNew().DecompressKnownSize(compressed, decompressedBuffer, decompressedSize); } public static int DecompressKnownSize(byte* compressed, byte* decompressedBuffer, int decompressedSize) { return LZ4DecompressorFactory.CreateNew().DecompressKnownSize(compressed, decompressedBuffer, decompressedSize); } public static byte[] Decompress(byte[] compressed) { return LZ4DecompressorFactory.CreateNew().Decompress(compressed); } public static int Decompress(byte[] compressed, byte[] decompressedBuffer) { return LZ4DecompressorFactory.CreateNew().Decompress(compressed, decompressedBuffer); } public static int Decompress(byte[] compressedBuffer, byte[] decompressedBuffer, int compressedSize) { return LZ4DecompressorFactory.CreateNew().Decompress(compressedBuffer, decompressedBuffer, compressedSize); } public static int Decompress( byte* compressedBuffer, byte* decompressedBuffer, int compressedSize, int maxDecompressedSize) { return LZ4DecompressorFactory.CreateNew().Decompress(compressedBuffer, decompressedBuffer, compressedSize, maxDecompressedSize); } } }