public void TestRoundtrip(string filename)
        {
            // Load
            byte[] decompressed = File.ReadAllBytes(filename);
            if (filename.EndsWith(".fse", StringComparison.OrdinalIgnoreCase))
            {
                var ms = new MemoryStream();
                using (var fse = new FseStream(new MemoryStream(decompressed), CompressionMode.Decompress, true))
                {
                    fse.CopyTo(ms);
                }
                decompressed = ms.ToArray();
            }

            // Compress
            var compressedStream = new MemoryStream();

            using (var fse = new FseStream(compressedStream, CompressionMode.Compress, true))
            {
                var ms = new MemoryStream(decompressed);
                ms.CopyTo(fse);
            }

            // Decompress
            compressedStream.Seek(0, SeekOrigin.Begin);
            var decompressedStream = new MemoryStream();

            using (var fse = new FseStream(compressedStream, CompressionMode.Decompress, true))
            {
                fse.CopyTo(decompressedStream);
            }

            // Compare
            decompressedStream.ToArray().AsSpan().SequenceCompareTo(decompressed);
        }
示例#2
0
        public void Setup()
        {
            using Stream stream = typeof(Program).Assembly.GetManifestResourceStream("FiniteStateEntropy.Benchmarks." + FileName);
            var ms = new MemoryStream();

            using var fse = new FseStream(stream, CompressionMode.Decompress, true);
            fse.CopyTo(ms);
            _decompressedData = ms.ToArray();
        }
        public void TestDecompress(string filename, string sha256)
        {
            using var ms = new MemoryStream();

            using var fs  = new FileStream(filename, FileMode.Open, FileAccess.Read);
            using var fse = new FseStream(fs, CompressionMode.Decompress, true);

            fse.CopyTo(ms);

            ms.Seek(0, SeekOrigin.Begin);
            byte[] actual = SHA256.Create().ComputeHash(ms);

            byte[] expected = HexHelper.StringToByteArray(sha256);

            Assert.True(actual.AsSpan().SequenceEqual(expected));
        }