From 5acf3e43ae4cbf3d16df70c68bbf5ad4d064b6e4 Mon Sep 17 00:00:00 2001 From: alcexhim Date: Sun, 8 Jun 2014 00:46:56 -0400 Subject: [PATCH] Implemented GzipCompressionModule using the .NET Gzip library --- .../Modules/Gzip/GzipCompressionModule.cs | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/CSharp/Libraries/UniversalEditor.Compression/Modules/Gzip/GzipCompressionModule.cs b/CSharp/Libraries/UniversalEditor.Compression/Modules/Gzip/GzipCompressionModule.cs index 44e20954..adc6d145 100644 --- a/CSharp/Libraries/UniversalEditor.Compression/Modules/Gzip/GzipCompressionModule.cs +++ b/CSharp/Libraries/UniversalEditor.Compression/Modules/Gzip/GzipCompressionModule.cs @@ -12,14 +12,34 @@ namespace UniversalEditor.Compression.Modules.Gzip get { return "gzip"; } } + public const int BUFFERSIZE = 4096; + protected override void CompressInternal(System.IO.Stream inputStream, System.IO.Stream outputStream) - { - throw new NotImplementedException(); + { + System.IO.Compression.GZipStream dst = new System.IO.Compression.GZipStream(outputStream, System.IO.Compression.CompressionMode.Compress); + int read = 0; + int start = 0; + do + { + byte[] buffer = new byte[BUFFERSIZE]; + read = inputStream.Read(buffer, start, buffer.Length); + dst.Write(buffer, 0, read); + } + while (read == BUFFERSIZE); } protected override void DecompressInternal(System.IO.Stream inputStream, System.IO.Stream outputStream, int inputLength, int outputLength) - { - throw new NotImplementedException(); + { + System.IO.Compression.GZipStream dst = new System.IO.Compression.GZipStream(inputStream, System.IO.Compression.CompressionMode.Decompress); + int read = 0; + int start = 0; + do + { + byte[] buffer = new byte[BUFFERSIZE]; + read = dst.Read(buffer, start, buffer.Length); + outputStream.Write(buffer, 0, read); + } + while (read == BUFFERSIZE); } } }