private void WriteFile(string fileName, string password, string internalName, bool remove = false) { var fullname = UnitTestInitializeCsv.GetTestPath(fileName); var encoding = EncodingHelper.GetEncoding(65001, true); const string c_Line1 = "This is a test of compressed data written to a file"; const string c_Line2 = "Yet another line to be written"; const string c_Line3 = "A text with non ASCII characters: Raphael Nöldner"; var sourceAccsss = new SourceAccess(fullname, false); if (string.IsNullOrEmpty(password)) { sourceAccsss.EncryptedPassphrase = password; } if (!string.IsNullOrEmpty(internalName)) { sourceAccsss.IdentifierInContainer = internalName; } using (var improvedStream = new ImprovedStream(sourceAccsss)) { using (var writer = new StreamWriter(improvedStream, encoding, 8192)) { writer.WriteLine(c_Line1); writer.WriteLine(c_Line2); writer.WriteLine(c_Line3); writer.WriteLine(); writer.WriteLine(c_Line1); } improvedStream.Close(); } Assert.IsTrue(FileSystemUtils.FileExists(fullname), "Check if File is created" + fileName); sourceAccsss = new SourceAccess(fullname, true); if (string.IsNullOrEmpty(password)) { sourceAccsss.EncryptedPassphrase = password; } using (var improvedStream = new ImprovedStream(sourceAccsss)) { using (var textReader = new StreamReader(improvedStream, encoding, true)) { Assert.AreEqual(c_Line1, textReader.ReadLine(), "Line 1 : " + fileName); Assert.AreEqual(c_Line2, textReader.ReadLine(), "Line 2 : " + fileName); Assert.AreEqual(c_Line3, textReader.ReadLine(), "Line 3 : " + fileName); Assert.AreEqual(string.Empty, textReader.ReadLine(), "Line 4 : " + fileName); Assert.AreEqual(c_Line1, textReader.ReadLine(), "Line 5 : " + fileName); } improvedStream.Close(); } if (remove) { FileSystemUtils.FileDelete(fullname); } }
public void OpenReadTestZipSmallRead() { var sourceAccess = new SourceAccess(UnitTestInitializeCsv.GetTestPath("AllFormatsPipe.zip"), true); // opeing without IdentifierInContainer should return teh first file entry using (var res = new ImprovedStream(sourceAccess)) { Assert.AreEqual("AllFormatsPipe.txt", sourceAccess.IdentifierInContainer); Assert.IsNotNull(res); var result1 = new byte[2048]; using (var reader = new BinaryReader(res)) { reader.Read(result1, 0, result1.Length); } // should return to teh start res.Seek(0, SeekOrigin.Begin); var result2 = new byte[2048]; using (var reader = new BinaryReader(res)) { reader.Read(result2, 0, result2.Length); } Assert.AreEqual(result1[0], result2[0]); Assert.AreEqual(result1[1], result2[1]); Assert.AreEqual(result1[2], result2[2]); Assert.AreEqual(result1[3], result2[3]); Assert.AreEqual(result1[4], result2[4]); Assert.AreEqual(result1[5], result2[5]); } // now sourceAccess.IdentifierInContainer is set, using (var res = new ImprovedStream(sourceAccess)) { Assert.IsNotNull(res); } }