public PortableData Create() { // 1. Decrypt stream ExportDataEncryptor decryptor = new ExportDataEncryptor(dataStream); using (MemoryStream decrypted = new MemoryStream()) { decryptor.Decrypt(decrypted); decrypted.Position = 0; // 2. Decompress stream ExportDataCompressor decompressor = new ExportDataCompressor(decrypted); using (MemoryStream decompressed = new MemoryStream()) { decompressor.Decompress(decompressed); decompressed.Position = 0; // 3. Deserialize stream PsaTracesSerializer deserializer = new PsaTracesSerializer(); PortableData result = deserializer.Deserialize(decompressed); return(result); } } }
public void XmlCompressionDecompressionTest() { FileStream stream = new FileStream("./compression/XmlFile.xml", FileMode.Open); ExportDataCompressor compressor = new ExportDataCompressor(stream); MemoryStream mems = new MemoryStream(); compressor.Compress(mems); mems.Position = 0; try { XDocument doc = XDocument.Load(mems); doc.ToString(); Assert.IsFalse(true); } catch (Exception) { mems.Position = 0; } MemoryStream mems2 = new MemoryStream(); mems.CopyTo(mems2); mems2.Flush(); mems2.Position = 0; ExportDataCompressor compressor2 = new ExportDataCompressor(mems2); MemoryStream decompressed = new MemoryStream(); compressor2.Decompress(decompressed); decompressed.Position = 0; XDocument doc2 = XDocument.Load(decompressed); XElement root = doc2.Root; Assert.IsTrue(root.HasElements); XElement xtag1 = root.Element("XmlTag1"); Assert.IsTrue(xtag1.Value == "XML Value 1"); }
public static PortableData Import(string vtsFilePathname) { if (String.IsNullOrEmpty(vtsFilePathname)) { throw new ArgumentNullException("vtsFilePathname"); } if (!File.Exists(vtsFilePathname)) { throw new ArgumentException(".VTS File does not exist."); } PortableData result; using (FileStream file = new FileStream(vtsFilePathname, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { file.Position = 0; ExportDataEncryptor decryptor = new ExportDataEncryptor(file); using (MemoryStream decryptedFile = new MemoryStream()) { decryptor.Decrypt(decryptedFile); //decryptedFile.Position = 0; ExportDataCompressor decompressor = new ExportDataCompressor(decryptedFile); using (MemoryStream decompressed = new MemoryStream()) { decompressor.Decompress(decompressed); decompressed.Position = 0; PsaTracesSerializer deserializer = new PsaTracesSerializer(); result = deserializer.Deserialize(decompressed); } } } return(result); }