public Decompress ( byte compressed, int compressedOffset, int compressedSize ) : byte[] | ||
compressed | byte | |
compressedOffset | int | |
compressedSize | int | |
return | byte[] |
public override int Read(byte[] buffer, int offset, int count) { if (compressionMode != CompressionMode.Decompress || decompressor == null) { throw new InvalidOperationException("Cannot read if not set to decompression mode."); } int readCount = 0; int firstByte = stream.ReadByte(); // first byte can indicate stream header, we just read it and move on. if (firstByte == StreamIdentifier) { CheckStreamHeader(); } else if (firstByte == UncompressedType) { var length = GetChunkUncompressedLength(); readCount = ProcessRemainingInternalBuffer(buffer, offset, count); if (readCount != count) { stream.Read(internalBuffer, 0, length); Array.Copy(internalBuffer, 0, buffer, offset, count - readCount); internalBufferIndex = count - readCount; internalBufferLength = length; } } else if (firstByte == CompressedType) { var length = GetChunkUncompressedLength(); count = ProcessRemainingInternalBuffer(buffer, offset, count); // we at most have 64kb in the buffer to read byte[] tempBuffer = new byte[1 << (BLOCK_LOG + 1)]; stream.Read(tempBuffer, 0, tempBuffer.Length); decompressor.Decompress(tempBuffer, 0, tempBuffer.Length, internalBuffer, 0, length); Array.Copy(internalBuffer, 0, buffer, offset, count); internalBufferIndex = count; internalBufferLength = length; } else if (firstByte > 0x2 && firstByte < 0x7f) { throw new InvalidOperationException("Found unskippable chunk type that cannot be undertood."); } else { // getting the length and skipping the data. var length = GetChunkUncompressedLength(); stream.Seek(length, SeekOrigin.Current); readCount += length; } return(readCount); }
public static byte[] Uncompress(byte[] compressed) { var target = new SnappyDecompressor(); return(target.Decompress(compressed, 0, compressed.Length)); }
public static byte[] Uncompress(byte[] compressed, int compressedOffset = 0, int compressedSize = -1) { return(decompressor.Decompress(compressed, compressedOffset, compressedSize >= 0 ? compressedSize : compressed.Length - compressedOffset)); }