public void Xz_EncoderCheckSHA256() { // 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 XzEncoder encoder = new XzEncoder(); encoder.Checksum = XzChecksum.SHA256; encoder.Encode(source, dest); // 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 (XzReader decompressor = new XzReader(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())); } } }
public void Xz_DecompressExternal() { // Decompress a stream created externally to this library using (XzReader reader = new XzReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("zuki.io.compression.test.thethreemusketeers.xz"))) { 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())); } } }