/// <summary>
 /// Decompress compressed bytes
 /// </summary>
 /// <param name="decompressor">Compressor to extend</param>
 /// <param name="data">The data to decompress</param>
 /// <returns></returns>
 public static byte[] Decompress(this IDecompressor decompressor, byte[] data)
 {
     using (var outputStream = new MemoryStream(data))
     {
         return(decompressor.Decompress(outputStream));
     }
 }
Example #2
0
        public void Execute()
        {
            while (generator.TryDequeue(out var info))
            {
                if (info.source.size > readBuffer.Length)
                {
                    readBuffer = new byte[info.source.size];
                }
                if (info.target.size > decompressBuffer.Length)
                {
                    decompressBuffer = new byte[info.target.size];
                }

                reader.Read(readBuffer, 0, info.source.size, info.source.offset);

                var decompressedSize = decompressor.Decompress(readBuffer, 0, info.source.size, decompressBuffer);

                if (decompressedSize != info.target.size)
                {
                    throw new Exception();
                }

                writer.Write(decompressBuffer, 0, info.target.size, info.target.offset);
            }
        }
        public void DecompressBytes()
        {
            const string targetFileName  = "someFile.txt";
            const string archiveFileName = "archive.gz";

            _fileHelperMock.Setup(fh => fh.ReadAllBytes(archiveFileName)).Returns(_compressedBytes);

            _decompressor.Decompress(archiveFileName, targetFileName);

            _fileHelperMock.Verify(fh => fh.WriteAllBytes(targetFileName, _expectedResult), Times.Once);
        }
Example #4
0
 /// <summary>
 /// Decompress compressed bytes
 /// </summary>
 /// <param name="decompressor">Compressor to extend</param>
 /// <param name="data">The data to decompress</param>
 /// <returns>A decompressed byte array.</returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static byte[] Decompress(this IDecompressor decompressor, byte[] data)
 {
     if (decompressor is null)
     {
         throw new ArgumentNullException(nameof(decompressor));
     }
     using (var outputStream = new MemoryStream(data))
     {
         return(decompressor.Decompress(outputStream));
     }
 }
Example #5
0
 private static int PerformDecompression(IDecompressor decompressor)
 {
     var(message, success) = decompressor.Decompress();
     if (decompressor is IDisposable disposableDecompressor)
     {
         disposableDecompressor.Dispose();
     }
     if (success)
     {
         return(0);
     }
     Console.WriteLine($"\r\nError: {message}");
     return(1);
 }
Example #6
0
        static bool Test(ICompressor compressor, IDecompressor decompressor, string inputFileName, string outputFileName, string restoredFileName)
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            var compressResult = compressor.Compress();

            stopWatch.Stop();
            if (compressor is IDisposable disposableCompressor)
            {
                disposableCompressor.Dispose();
            }
            var compressionTime = stopWatch.ElapsedMilliseconds;

            if (!compressResult.success)
            {
                return(false);
            }
            Console.WriteLine($"Output file size:\t{new FileInfo(outputFileName).Length} bytes");

            stopWatch.Reset();
            stopWatch.Start();
            var decompressResult = decompressor.Decompress();

            stopWatch.Stop();
            if (decompressor is IDisposable disposableDecompressor)
            {
                disposableDecompressor.Dispose();
            }
            var decompressionTime = stopWatch.ElapsedMilliseconds;

            if (!decompressResult.success)
            {
                return(false);
            }
            Console.WriteLine($"Restored file size:\t{new FileInfo(restoredFileName).Length} bytes");
            Console.WriteLine($"Compression time:\t{compressionTime} ms");
            Console.WriteLine($"Decompression time:\t{decompressionTime} ms");
            return(FileEquals(inputFileName, restoredFileName));
        }
Example #7
0
 public void Decompress(string archiveFileName, string targetFileName)
 {
     _decompressor.Decompress(archiveFileName, targetFileName);
 }
 private byte[][] DecompressThreadSafely(int threadIndex,
                                         byte[][] bufferAccumulator, byte[] bufferReader)
 {
     bufferAccumulator[threadIndex] = _decompressor.Decompress(bufferReader);
     return(bufferAccumulator);
 }