Beispiel #1
0
        public void Unzipped_file_has_the_same_hash_as_the_original()
        {
            var originalFileHash = _fixture.FileHash;
            var filePath         = _fixture.FilePath;

            var sw = Stopwatch.StartNew();

            {
                using var incomingStream = new FileStream(filePath, FileMode.Open);
                using var outgoingStream = new FileStream(filePath + ".bz", FileMode.Create);

                var compressor = new BZipCompressor(incomingStream, outgoingStream);
                compressor.Compress();
            }

            {
                using var incomingStream = new FileStream(filePath + ".bz", FileMode.Open);
                using var outgoingStream = new FileStream(filePath + ".unzip", FileMode.Create);

                var decompressor = new BZipDecompressor(incomingStream, outgoingStream);
                decompressor.Decompress();
            }

            using var unzippedFile = new FileStream(filePath + ".unzip", FileMode.Open);

            using var md5 = MD5.Create();
            var actualHash = md5.ComputeHash(unzippedFile);

            Assert.Equal(originalFileHash, actualHash);

            _output.WriteLine(sw.Elapsed.ToString());
        }
        public void Compressor()
        {
            using var incomingStream = File.OpenRead("D:/temp/1gb.bin");
            using var outgoingStream = File.OpenWrite("D:/temp/1gb.bz");

            var options = new BZipArchiverOptions(
                chunksToProcessBoundedCapacity: ChunksBoundedCapacity,
                chunksToWriteBoundedCapacity: ChunksBoundedCapacity);

            var compressor = new BZipCompressor(incomingStream, outgoingStream, options);

            compressor.Compress();
        }