public void round_trip_returns_original_data(string fileName) { byte[] uncompressed = File.ReadAllBytes(fileName); var target = new SnappyCompressor(); var result = new byte[target.MaxCompressedLength(uncompressed.Length)]; int size = target.Compress(uncompressed, 0, uncompressed.Length, result); var target2 = new SnappyDecompressor(); var sizes = target2.ReadUncompressedLength(result, 0); var bytes = new byte[sizes[0]]; target2.Decompress(result, 0 + sizes[1], size - sizes[1], bytes, 0, sizes[1]); Assert.Equal(uncompressed, bytes); }
public void compress_writes_uncompressed_length_first(int dataSize, int storageBytes) { var data = GetRandomData(dataSize); var target = new SnappyCompressor(); int compressedSize = target.MaxCompressedLength(data.Length); var compressed = new byte[compressedSize]; target.Compress(data, 0, data.Length, compressed); var decompressor = new SnappyDecompressor(); var result = decompressor.ReadUncompressedLength(compressed, 0); Assert.Equal(dataSize, result[0]); Assert.Equal(storageBytes, result[1]); }
public void round_trip_returns_original_data(string fileName) { byte[] uncompressed = File.ReadAllBytes(fileName); var target = new SnappyCompressor(); var result = new byte[target.MaxCompressedLength(uncompressed.Length)]; int size = target.Compress(uncompressed, 0, uncompressed.Length, result); var target2 = new SnappyDecompressor(); var sizes = target2.ReadUncompressedLength(result, 0); var bytes = new byte[sizes[0]]; target2.Decompress(result, 0 + sizes[1], size - sizes[1], bytes, 0, sizes[1]); Assert.Equal(uncompressed, bytes); }
private static int[] ReadLengthData(byte[] data) { var target = new SnappyDecompressor(); return target.ReadUncompressedLength(data, 0); }
public static int GetUncompressedLength(byte[] compressed, int offset, int count) { var decompressor = new SnappyDecompressor(); return(decompressor.ReadUncompressedLength(compressed, offset, count)[0]); }
public void compress_writes_uncompressed_length_first(int dataSize, int storageBytes) { var data = GetRandomData(dataSize); var target = new SnappyCompressor(); int compressedSize = target.MaxCompressedLength(data.Length); var compressed = new byte[compressedSize]; target.Compress(data, 0, data.Length, compressed); var decompressor = new SnappyDecompressor(); var result = decompressor.ReadUncompressedLength(compressed, 0); Assert.Equal(dataSize, result[0]); Assert.Equal(storageBytes, result[1]); }
private static int[] ReadLengthData(byte[] data) { var target = new SnappyDecompressor(); return(target.ReadUncompressedLength(data, 0)); }
/// <summary> /// Get the uncompressed data length from a compressed Snappy block. /// </summary> /// <param name="input">Compressed snappy block.</param> /// <returns>The length of the uncompressed data in the block.</returns> /// <exception cref="InvalidDataException">The data in <paramref name="input"/> has an invalid length.</exception> /// <remarks> /// This is useful for allocating a sufficient output buffer before calling <see cref="Decompress"/>. /// </remarks> public static int GetUncompressedLength(ReadOnlySpan <byte> input) => SnappyDecompressor.ReadUncompressedLength(input);