Esempio n. 1
0
        private static byte[] BZip2Decompress(Stream data, int expectedLength)
        {
            using (MemoryStream output = new MemoryStream(expectedLength))
            {
#if WITH_DOTNETZIP
                using (var stream = new Ionic.BZip2.BZip2InputStream(data, false))
                {
                    stream.CopyTo(output);
                }
#elif WITH_BZIP2NET
                using (var stream = new Bzip2.BZip2InputStream(data, false))
                {
                    stream.CopyTo(output);
                }
#elif WITH_SHARPCOMPRESS
                /*
                 * using (var stream = new SharpCompress.Compressors.BZip2.BZip2Stream(data, SharpCompress.Compressors.CompressionMode.Decompress, false))
                 * {
                 *  stream.CopyTo(output);
                 * }
                 */
#elif WITH_SHARPZIPLIB
                ICSharpCode.SharpZipLib.BZip2.BZip2.Decompress(data, output, true);
#else
                throw new NotImplementedException("Please define which compression library you want to use");
#endif
                return(output.ToArray());
            }
        }
 public byte[] Transform(byte[] content)
 {
     using (var contentStream = new MemoryStream(content))
     using (var bzipStream = new Ionic.BZip2.BZip2InputStream(contentStream))
     using (var memoryStreamDecompressed = new MemoryStream())
     {
         bzipStream.CopyTo(memoryStreamDecompressed);
         var bytes = memoryStreamDecompressed.ToArray();
         return bytes;
     }
 }
        private static byte[] BZip2Decompress(Stream data, int expectedLength)
        {
            using (MemoryStream output = new MemoryStream(expectedLength))
            {
                using (var stream = new Ionic.BZip2.BZip2InputStream(data))
                {
                    stream.CopyTo(output);
                }

                return(output.ToArray());
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Decompresses the input stream.
        /// </summary>
        /// <param name="data">Stream containing compressed data.</param>
        /// <param name="expectedLength">The expected length (in bytes) of the decompressed data.</param>
        /// <returns>Byte array containing the decompressed data.</returns>
        public static byte[] Decompress(Stream data, uint expectedLength)
        {
            using (var output = new MemoryStream((int)expectedLength))
            {
#if true
                using var bZip2InputStream = new Ionic.BZip2.BZip2InputStream(data, true);
                bZip2InputStream.CopyTo(output);
#else
                ICSharpCode.SharpZipLib.BZip2.BZip2.Decompress(data, output, false);
#endif
                return(output.ToArray());
            }
        }