예제 #1
0
        public void Lz4_CompressDecompress()
        {
            // Start with a MemoryStream created from the sample data
            using (MemoryStream source = new MemoryStream(s_sampledata))
            {
                using (MemoryStream dest = new MemoryStream())
                {
                    // Compress the data into the destination memory stream instance
                    using (Lz4Writer compressor = new Lz4Writer(dest, CompressionLevel.Optimal, true)) source.CopyTo(compressor);

                    // The compressed data should be smaller than the source data
                    Assert.IsTrue(dest.Length < source.Length);

                    source.SetLength(0);                                // Clear the source stream
                    dest.Position = 0;                                  // Reset the destination stream

                    // Decompress the data back into the source memory stream
                    using (Lz4Reader decompressor = new Lz4Reader(dest, true)) decompressor.CopyTo(source);

                    // Ensure that the original data has been restored
                    Assert.AreEqual(source.Length, s_sampledata.Length);
                    Assert.IsTrue(s_sampledata.SequenceEqual(source.ToArray()));
                }
            }
        }
예제 #2
0
        public void Lz4_DecompressExternal()
        {
            // Decompress a stream created externally to this library
            using (Lz4Reader reader = new Lz4Reader(Assembly.GetExecutingAssembly().GetManifestResourceStream("zuki.io.compression.test.thethreemusketeers.lz4")))
            {
                using (MemoryStream dest = new MemoryStream())
                {
                    reader.CopyTo(dest);
                    dest.Flush();

                    // Verify that the output matches the sample data byte-for-byte
                    Assert.IsTrue(Enumerable.SequenceEqual(s_sampledata, dest.ToArray()));
                }
            }
        }