-
Notifications
You must be signed in to change notification settings - Fork 0
Compression
Paul Hirch edited this page May 13, 2024
·
4 revisions
Expansion methods for BinaryView, found under the Grille.IO.Compression
namespace.
These methods utilize the built-in compression streams under System.IO.Compression
Because of limitations of the CompressionStream classes, sections always need a length prefix.
using var bw = new BinaryViewWriter(stream);
// write uncompressed
// Creates and CompressionStream and pushes it onto stack.
bw.BeginCompressedSection(CompressionType.Deflate);
// write compressed
// Pops CompressionStream from stack, write length prefix and, copy compresed data to peak stream.
bw.EndCompressedSection();
// write uncompressed
using var br = new BinaryViewReader(stream);
// read uncompressed
// Read length prefix, Creates DecompressionStream and copy compressed data into it.
br.BeginCompressedSection(CompressionType.Deflate);
// read compressed
// Pops DecompressionStream from stack.
br.EndCompressedSection();
// read uncompressed
Using syntax is also supported.
using var bw = new BinaryViewWriter(stream);
// write uncompressed
using (bw.BeginCompressedSection(CompressionType.Deflate))
{
// write compressed
}
// write uncompressed
Compresses/Decompresses all data after this statement. A length prefix is not needed.
using var bw = new BinaryViewWriter(stream);
// write uncompressed
// Creates CompressionStream and pushes it onto stack.
bw.CompressAll(CompressionType.Deflate);
// write compressed
using var br = new BinaryViewReader(stream);
// read uncompressed
// Creat and push DecompressionStream and copy all data after into it.
br.DecompressAll(CompressionType.Deflate);
// read compressed