protected void DecompressButton_Click(object sender, EventArgs e) { var bytes = System.Convert.FromBase64String(CompressedTextBox.Text); var srcStream = new System.IO.MemoryStream(bytes); var dstStream = new System.IO.MemoryStream(); srcStream.Position = 0; var stream = new DeflateStream2(srcStream, System.IO.Compression.CompressionMode.Decompress); //Copy the decompression stream into the output file. //------------------------------------------------- byte[] buffer = new byte[4096]; int numRead; while ((numRead = stream.Read(buffer, 0, buffer.Length)) != 0) { dstStream.Write(buffer, 0, numRead); } //------------------------------------------------- //stream.CopyTo(dstStream); //------------------------------------------------- dstStream.Close(); var text = System.Text.Encoding.UTF8.GetString(dstStream.ToArray()); DecompressedTextBox.Text = text; LogTextBox.Text += string.Format("Decompress: srcStream.length = {0}, dstStream.Length = {1}\r\n", srcStream.Length, dstStream.ToArray().Length); }
protected void CompressButton_Click(object sender, EventArgs e) { var text = DecompressedTextBox.Text; var bytes = System.Text.Encoding.UTF8.GetBytes(text); var srcStream = new System.IO.MemoryStream(bytes); var dstStream = new System.IO.MemoryStream(); srcStream.Position = 0; var stream = new DeflateStream2(dstStream, System.IO.Compression.CompressionMode.Compress); // Copy the source file into the compression stream. //------------------------------------------------- //srcStream.WriteTo(stream); //------------------------------------------------- byte[] buffer = new byte[4096]; int numRead; while ((numRead = srcStream.Read(buffer, 0, buffer.Length)) != 0) { stream.Write(buffer, 0, numRead); } //------------------------------------------------- stream.Close(); var base64 = System.Convert.ToBase64String(dstStream.ToArray()); CompressedTextBox.Text = base64; LogTextBox.Text += string.Format("Compress: srcStream.length = {0}, dstStream.Length = {1}\r\n", srcStream.Length, dstStream.ToArray().Length); }