コード例 #1
0
        protected override byte[] Decompress(Stream compressed, out UInt128 compressedHash)
        {
            var header = new byte[9];
            int read   = 0;

            do
            {
                read += compressed.Read(header, read, header.Length - read);
            } while (read < header.Length);
            if (header[0] != Header[0])
            {
                throw new FormatException($"Invalid header value {header[0]}");
            }

            var compressedSize   = BitConverter.ToInt32(header, 1);
            var uncompressedSize = BitConverter.ToInt32(header, 5);

            read            = 0;
            compressedSize -= header.Length;
            var compressedBytes = new byte[compressedSize + header.Length];

            Array.Copy(header, 0, compressedBytes, 0, header.Length);
            do
            {
                read += compressed.Read(compressedBytes, header.Length + read, compressedSize - read);
            } while (read < compressedSize);
            compressedHash = ClickHouseCityHash.CityHash128(compressedBytes);
            return(LZ4Codec.Decode(compressedBytes, header.Length, compressedSize, uncompressedSize));
        }
コード例 #2
0
        public override void EndCompression()
        {
            var compressed = Compress(_uncompressed);
            var hash       = ClickHouseCityHash.CityHash128(compressed);

            _baseStream.Write(BitConverter.GetBytes(hash.Low), 0, 8);
            _baseStream.Write(BitConverter.GetBytes(hash.High), 0, 8);
            _baseStream.Write(compressed, 0, compressed.Length);
        }