コード例 #1
0
        public void GzipDeflateEncodingDecodeDeflate()
        {
            byte[] encoded;

            using (MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(GzipDeflateEncodingTests.Content)))
            {
                using (MemoryStream outputStream = new MemoryStream())
                {
                    using (DeflateStream compressionStream = new DeflateStream(outputStream, CompressionMode.Compress))
                    {
                        stream.CopyTo(compressionStream);
                    }

                    encoded = outputStream.ToArray();
                }
            }

            using (Stream stream = new MemoryStream(encoded))
            {
                Stream decodeStream = null;

                try
                {
                    decodeStream = new GzipDeflateEncoding().Decode(EncodingType.Parse("deflate"), stream);

                    using (StreamReader reader = new StreamReader(decodeStream, Encoding.Unicode))
                    {
                        decodeStream = null;
                        Assert.AreEqual(GzipDeflateEncodingTests.Content, reader.ReadToEnd());
                    }
                }
                finally
                {
                    if (decodeStream != null)
                    {
                        decodeStream.Dispose();
                    }
                }
            }
        }
コード例 #2
0
        public void GzipDeflateEncodingEncodeGzip()
        {
            byte[] encoded, comparison;

            using (MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(GzipDeflateEncodingTests.Content)))
            {
                using (MemoryStream outputStream = new MemoryStream())
                {
                    using (Stream encodeStream = new GzipDeflateEncoding().Encode(EncodingType.Parse("gzip"), outputStream))
                    {
                        stream.CopyTo(encodeStream);
                    }

                    encoded = outputStream.ToArray();
                }
            }

            using (MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(GzipDeflateEncodingTests.Content)))
            {
                using (MemoryStream outputStream = new MemoryStream())
                {
                    using (GZipStream compressionStream = new GZipStream(outputStream, CompressionMode.Compress))
                    {
                        stream.CopyTo(compressionStream);
                    }

                    comparison = outputStream.ToArray();
                }
            }

            Assert.IsTrue(encoded.SequenceEqual(comparison));
        }