/// <summary>
 /// Compress an array of bytes that represent the gray scale thumbnail
 /// </summary>
 /// <param name="inputGrayScaleThumb"></param>
 /// <returns></returns>
 public static byte[] CompressedGrayScaleThumb(byte[] inputGrayScaleThumb)
 {
     using (var outputStream = new MemoryStream())
         using (var arithmeticStream = new ArithmeticStream(outputStream, CompressionMode.Compress, true))
         {
             arithmeticStream.Write(inputGrayScaleThumb, 0, inputGrayScaleThumb.Length);
             arithmeticStream.Flush();
             arithmeticStream.Close();
             return(outputStream.ToArray());
         }
 }
 /// <summary>
 /// Decompress an array of bytes that represent the gray scale thumbnail
 /// </summary>
 /// <param name="compressedGrayScaleThumb"></param>
 /// <returns></returns>
 public static byte[] DecompressGrayScaleThumb(byte[] compressedGrayScaleThumb)
 {
     using (var inputStream = new MemoryStream(compressedGrayScaleThumb))
         using (var arithmeticStream = new ArithmeticStream(inputStream, CompressionMode.Decompress, true))
             using (var outputStream = new MemoryStream())
             {
                 arithmeticStream.CopyTo(outputStream);
                 arithmeticStream.Flush();
                 outputStream.Flush();
                 outputStream.Close();
                 return(outputStream.ToArray());
             }
 }
Example #3
0
        public void Verify27K()
        {
            byte[] data = Encoding.UTF8.GetBytes(TestResources.RFC5_Text);

            var stream  = new MemoryStream();
            var encoder = new ArithmeticStream(stream, CompressionMode.Compress, true);

            encoder.Write(data, 0, data.Length);
            encoder.Flush();

            stream.Position = 0;

            var decoder = new ArithmeticStream(stream, CompressionMode.Decompress, true);
            var decoded = new byte[data.Length];

            decoder.Read(decoded, 0, decoded.Length);

            CollectionAssert.AreEqual(data, decoded);

            Assert.AreEqual(16236, stream.Length);
        }
        public void Verify27K()
        {
            byte[] data = Encoding.UTF8.GetBytes(TestResources.RFC5_Text);

            var stream = new MemoryStream();
            var encoder = new ArithmeticStream(stream, CompressionMode.Compress, true);

            encoder.Write(data, 0, data.Length);
            encoder.Flush();

            stream.Position = 0;

            var decoder = new ArithmeticStream(stream, CompressionMode.Decompress, true);
            var decoded = new byte[data.Length];

            decoder.Read(decoded, 0, decoded.Length);

            CollectionAssert.AreEqual(data, decoded);

            Assert.AreEqual(16236, stream.Length);
        }