Пример #1
0
        public int Decompress(CompressedFile file, CompressionLevel level) // the level argument is not used here, but it describes how the data was compressed
        {
            file.CompressedDataStream.Position = 0;

            var compressor = CreateStream(file.CompressedDataStream, CompressionMode.Decompress);

            return(compressor.Read(file.UncompressedData, 0, file.UncompressedData.Length));
        }
Пример #2
0
        public void Compress(CompressedFile file, CompressionLevel level)
        {
            file.CompressedDataStream.Position = 0; // all benchmarks invocation reuse the same stream, we set Postion to 0 to start at the beginning

            var compressor = CreateStream(file.CompressedDataStream, level);

            compressor.Write(file.UncompressedData, 0, file.UncompressedData.Length);
        }
Пример #3
0
        public Span <byte> Decompress_WithState(CompressedFile file, CompressionLevel level) // the level argument is not used here, but it describes how the data was compressed
        {
            using (BrotliDecoder decoder = new BrotliDecoder())
            {
                Span <byte>         output = new Span <byte>(file.UncompressedData);
                ReadOnlySpan <byte> input  = file.CompressedData;
                while (!input.IsEmpty && !output.IsEmpty)
                {
                    decoder.Decompress(input, output, out int bytesConsumed, out int written);
                    input  = input.Slice(bytesConsumed);
                    output = output.Slice(written);
                }

                return(output);
            }
        }
Пример #4
0
        public Span <byte> Compress_WithState(CompressedFile file, CompressionLevel level)
        {
            using (BrotliEncoder encoder = new BrotliEncoder(GetQuality(level), Window))
            {
                Span <byte>         output = new Span <byte>(file.UncompressedData);
                ReadOnlySpan <byte> input  = file.CompressedData;
                while (!input.IsEmpty && !output.IsEmpty)
                {
                    encoder.Compress(input, output, out int bytesConsumed, out int written, isFinalBlock: false);
                    input  = input.Slice(bytesConsumed);
                    output = output.Slice(written);
                }
                encoder.Compress(input, output, out int bytesConsumed2, out int written2, isFinalBlock: true);

                return(output);
            }
        }
 public void Setup() => CompressedFile = new CompressedFile(file, level, CreateStream); // this logic is quite expensive, needs to be a part of Setup
Пример #6
0
 public bool Compress_WithoutState(CompressedFile file, CompressionLevel level)
 => BrotliEncoder.TryCompress(file.UncompressedData, file.UncompressedData, out int bytesWritten, GetQuality(level), Window);