internal CabUnpacker(CabEngine cabEngine) : base(cabEngine) { this.fdiAllocMemHandler = this.CabAllocMem; this.fdiFreeMemHandler = this.CabFreeMem; this.fdiOpenStreamHandler = this.CabOpenStream; this.fdiReadStreamHandler = this.CabReadStream; this.fdiWriteStreamHandler = this.CabWriteStream; this.fdiCloseStreamHandler = this.CabCloseStream; this.fdiSeekStreamHandler = this.CabSeekStream; this.fdiHandle = NativeMethods.FDI.Create( this.fdiAllocMemHandler, this.fdiFreeMemHandler, this.fdiOpenStreamHandler, this.fdiReadStreamHandler, this.fdiWriteStreamHandler, this.fdiCloseStreamHandler, this.fdiSeekStreamHandler, NativeMethods.FDI.CPU_80386, this.ErfHandle.AddrOfPinnedObject()); if (this.Erf.Error) { int error = this.Erf.Oper; int errorCode = this.Erf.Type; this.ErfHandle.Free(); throw new CabException( error, errorCode, CabException.GetErrorMessage(error, errorCode, true)); } }
public CabUnpacker(CabEngine cabEngine) : base(cabEngine) { this.fdiAllocMemHandler = this.CabAllocMem; this.fdiFreeMemHandler = this.CabFreeMem; this.fdiOpenStreamHandler = this.CabOpenStream; this.fdiReadStreamHandler = this.CabReadStream; this.fdiWriteStreamHandler = this.CabWriteStream; this.fdiCloseStreamHandler = this.CabCloseStream; this.fdiSeekStreamHandler = this.CabSeekStream; this.fdiHandle = NativeMethods.FDI.Create( this.fdiAllocMemHandler, this.fdiFreeMemHandler, this.fdiOpenStreamHandler, this.fdiReadStreamHandler, this.fdiWriteStreamHandler, this.fdiCloseStreamHandler, this.fdiSeekStreamHandler, NativeMethods.FDI.CPU_80386, this.ErfHandle.AddrOfPinnedObject()); if (this.Erf.Error) { int error = this.Erf.Oper; int errorCode = this.Erf.Type; this.ErfHandle.Free(); throw new CabException( error, errorCode, CabException.GetErrorMessage(error, errorCode, true)); } }
protected void OnProgress(ArchiveProgressType progressType) { if (!suppressProgressEvents) { ArchiveProgressEventArgs e = new ArchiveProgressEventArgs(progressType, currentFileName, (currentFileNumber >= 0) ? currentFileNumber : 0, totalFiles, currentFileBytesProcessed, currentFileTotalBytes, currentArchiveName, currentArchiveNumber, totalArchives, currentArchiveBytesProcessed, currentArchiveTotalBytes, fileBytesProcessed, totalFileBytes); CabEngine.ReportProgress(e); } }
protected CabWorker(CabEngine cabEngine) { this.cabEngine = cabEngine; streamHandles = new HandleManager <Stream>(); erf = new NativeMethods.ERF(); erfHandle = GCHandle.Alloc(erf, GCHandleType.Pinned); cabNumbers = new Dictionary <string, short>(1); buf = new byte[32768]; }
public static Stream Unpack(Stream compressedStream) { CabEngine cabEngine = new CabEngine(); InMemoryUnpackContext unpackContext = new InMemoryUnpackContext(compressedStream); cabEngine.Unpack(unpackContext, suffix => true); Stream s = unpackContext.UncompressedStream; s.Seek(0, SeekOrigin.Begin); return s; }
protected CabWorker(CabEngine cabEngine) { this.cabEngine = cabEngine; this.streamHandles = new HandleManager <Stream>(); this.erf = new NativeMethods.ERF(); this.erfHandle = GCHandle.Alloc(this.erf, GCHandleType.Pinned); this.cabNumbers = new Dictionary <string, short>(1); // 32K seems to be the size of the largest chunks processed by cabinet.dll. // But just in case, this buffer will auto-enlarge. this.buf = new byte[32768]; }
public void CabBadPackStreamContexts() { string[] testFiles = new string[] { "test.txt" }; CompressionTestUtil.GenerateRandomFile(testFiles[0], 0, 20000); using (CabEngine cabEngine = new CabEngine()) { cabEngine.CompressionLevel = CompressionLevel.None; CompressionTestUtil.TestBadPackStreamContexts(cabEngine, "test.cab", testFiles); } }
protected CabWorker(CabEngine cabEngine) { this.cabEngine = cabEngine; this.streamHandles = new HandleManager<Stream>(); this.erf = new NativeMethods.ERF(); this.erfHandle = GCHandle.Alloc(this.erf, GCHandleType.Pinned); this.cabNumbers = new Dictionary<string, short>(1); // 32K seems to be the size of the largest chunks processed by cabinet.dll. // But just in case, this buffer will auto-enlarge. this.buf = new byte[32768]; }
public void CabBadUnpackStreamContexts() { int txtSize = 40960; CabInfo cabInfo = new CabInfo("test2.cab"); CompressionTestUtil.GenerateRandomFile("cabtest-0.txt", 0, txtSize); CompressionTestUtil.GenerateRandomFile("cabtest-1.txt", 1, txtSize); cabInfo.PackFiles(null, new string[] { "cabtest-0.txt", "cabtest-1.txt" }, null); using (CabEngine cabEngine = new CabEngine()) { CompressionTestUtil.TestBadUnpackStreamContexts(cabEngine, "test2.cab"); } }
public CabPacker(CabEngine cabEngine) : base(cabEngine) { _fciAllocMemHandler = CabAllocMem; _fciFreeMemHandler = CabFreeMem; _fciOpenStreamHandler = CabOpenStreamEx; _fciReadStreamHandler = CabReadStreamEx; _fciWriteStreamHandler = CabWriteStreamEx; _fciCloseStreamHandler = CabCloseStreamEx; _fciSeekStreamHandler = CabSeekStreamEx; _fciFilePlacedHandler = CabFilePlaced; _fciDeleteFileHandler = CabDeleteFile; _fciGetTempFileHandler = CabGetTempFile; _fciGetNextCabinet = CabGetNextCabinet; _fciCreateStatus = CabCreateStatus; _fciGetOpenInfo = CabGetOpenInfo; _tempStreams = new List <Stream>(); CompressionLevel = CompressionLevel.Normal; }
public CabPacker(CabEngine cabEngine) : base(cabEngine) { this.fciAllocMemHandler = this.CabAllocMem; this.fciFreeMemHandler = this.CabFreeMem; this.fciOpenStreamHandler = this.CabOpenStreamEx; this.fciReadStreamHandler = this.CabReadStreamEx; this.fciWriteStreamHandler = this.CabWriteStreamEx; this.fciCloseStreamHandler = this.CabCloseStreamEx; this.fciSeekStreamHandler = this.CabSeekStreamEx; this.fciFilePlacedHandler = this.CabFilePlaced; this.fciDeleteFileHandler = this.CabDeleteFile; this.fciGetTempFileHandler = this.CabGetTempFile; this.fciGetNextCabinet = this.CabGetNextCabinet; this.fciCreateStatus = this.CabCreateStatus; this.fciGetOpenInfo = this.CabGetOpenInfo; this.tempStreams = new List<Stream>(); this.compressionLevel = CompressionLevel.Normal; }
public CabUnpacker(CabEngine cabEngine) : base(cabEngine) { fdiAllocMemHandler = base.CabAllocMem; fdiFreeMemHandler = base.CabFreeMem; fdiOpenStreamHandler = base.CabOpenStream; fdiReadStreamHandler = base.CabReadStream; fdiWriteStreamHandler = base.CabWriteStream; fdiCloseStreamHandler = base.CabCloseStream; fdiSeekStreamHandler = base.CabSeekStream; fdiHandle = NativeMethods.FDI.Create(fdiAllocMemHandler, fdiFreeMemHandler, fdiOpenStreamHandler, fdiReadStreamHandler, fdiWriteStreamHandler, fdiCloseStreamHandler, fdiSeekStreamHandler, 1, base.ErfHandle.AddrOfPinnedObject()); if (base.Erf.Error) { int oper = base.Erf.Oper; int type = base.Erf.Type; base.ErfHandle.Free(); throw new CabException(oper, type, CabException.GetErrorMessage(oper, type, extracting: true)); } }
protected void OnProgress(ArchiveProgressType progressType) { if (!SuppressProgressEvents) { var e = new ArchiveProgressEventArgs( progressType, CurrentFileName, CurrentFileNumber >= 0 ? CurrentFileNumber : 0, TotalFiles, CurrentFileBytesProcessed, CurrentFileTotalBytes, CurrentArchiveName, CurrentArchiveNumber, TotalArchives, CurrentArchiveBytesProcessed, CurrentArchiveTotalBytes, FileBytesProcessed, TotalFileBytes); CabEngine.ReportProgress(e); } }
public void CabinetUtfPaths() { string[] files = new string[] { "어그리먼트送信ポート1ßà_Agreement.txt", "콘토소ßà_MyProfile.txt", "파트너1ßà_PartnerProfile.txt", }; string dirA = "utf8-A"; if (Directory.Exists(dirA)) Directory.Delete(dirA, true); Directory.CreateDirectory(dirA); string dirB = "utf8-B"; if (Directory.Exists(dirB)) Directory.Delete(dirB, true); Directory.CreateDirectory(dirB); int txtSize = 1024; CompressionTestUtil.GenerateRandomFile(Path.Combine(dirA, files[0]), 0, txtSize); CompressionTestUtil.GenerateRandomFile(Path.Combine(dirA, files[1]), 1, txtSize); CompressionTestUtil.GenerateRandomFile(Path.Combine(dirA, files[2]), 2, txtSize); ArchiveFileStreamContext streamContextA = new ArchiveFileStreamContext("utf8.cab", dirA, null); using (CabEngine cabEngine = new CabEngine()) { cabEngine.Pack(streamContextA, files); } ArchiveFileStreamContext streamContextB = new ArchiveFileStreamContext("utf8.cab", dirB, null); using (CabEngine cex = new CabEngine()) { cex.Unpack(streamContextB, null); } bool directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB); Assert.IsTrue(directoryMatch, "Testing whether cabinet output directory matches input directory."); }
public void CabinetOffset() { int txtSize = 10240; CompressionTestUtil.GenerateRandomFile("test.txt", 0, txtSize); CompressionTestUtil.GenerateRandomFile("base.txt", 1, 2 * txtSize + 4); ArchiveFileStreamContext streamContext = new ArchiveFileStreamContext("base.txt", null, null); streamContext.EnableOffsetOpen = true; using (CabEngine cabEngine = new CabEngine()) { cabEngine.Pack(streamContext, new string[] { "test.txt" }); } Assert.IsTrue(new FileInfo("base.txt").Length > 2 * txtSize + 4); string saveText; using (Stream txtStream = File.OpenRead("test.txt")) { saveText = new StreamReader(txtStream).ReadToEnd(); } File.Delete("test.txt"); using (CabEngine cex = new CabEngine()) { cex.Unpack(streamContext, null); } string testText; using (Stream txtStream = File.OpenRead("test.txt")) { testText = new StreamReader(txtStream).ReadToEnd(); } Assert.AreEqual<string>(saveText, testText); }
public void CabinetExtractUpdate() { int fileCount = 5, fileSize = 2048; string dirA = String.Format("{0}-{1}-A", fileCount, fileSize); if (Directory.Exists(dirA)) Directory.Delete(dirA, true); Directory.CreateDirectory(dirA); string dirB = String.Format("{0}-{1}-B", fileCount, fileSize); if (Directory.Exists(dirB)) Directory.Delete(dirB, true); Directory.CreateDirectory(dirB); string[] files = new string[fileCount]; for (int iFile = 0; iFile < fileCount; iFile++) { files[iFile] = "€" + iFile + ".txt"; CompressionTestUtil.GenerateRandomFile(Path.Combine(dirA, files[iFile]), iFile, fileSize); } CabInfo cabInfo = new CabInfo("testupdate.cab"); cabInfo.Pack(dirA); cabInfo.Unpack(dirB); DateTime originalTime = File.GetLastWriteTime(Path.Combine(dirA, "€1.txt")); DateTime pastTime = originalTime - new TimeSpan(0, 5, 0); DateTime futureTime = originalTime + new TimeSpan(0, 5, 0); using (CabEngine cabEngine = new CabEngine()) { string cabName = "testupdate.cab"; ArchiveFileStreamContext streamContext = new ArchiveFileStreamContext(cabName, dirB, null); streamContext.ExtractOnlyNewerFiles = true; Assert.AreEqual<bool>(true, streamContext.ExtractOnlyNewerFiles); Assert.IsNotNull(streamContext.ArchiveFiles); Assert.AreEqual<int>(1, streamContext.ArchiveFiles.Count); Assert.AreEqual<string>(cabName, streamContext.ArchiveFiles[0]); Assert.AreEqual<string>(dirB, streamContext.Directory); File.SetLastWriteTime(Path.Combine(dirB, "€1.txt"), futureTime); cabEngine.Unpack(streamContext, null); Assert.IsTrue(File.GetLastWriteTime(Path.Combine(dirB, "€1.txt")) - originalTime > new TimeSpan(0, 4, 55)); File.SetLastWriteTime(Path.Combine(dirB, "€1.txt"), pastTime); File.SetLastWriteTime(Path.Combine(dirB, "€2.txt"), pastTime); File.SetAttributes(Path.Combine(dirB, "€2.txt"), FileAttributes.ReadOnly); File.SetAttributes(Path.Combine(dirB, "€2.txt"), FileAttributes.Hidden); File.SetAttributes(Path.Combine(dirB, "€2.txt"), FileAttributes.System); cabEngine.Unpack(streamContext, null); Assert.IsTrue((File.GetLastWriteTime(Path.Combine(dirB, "€1.txt")) - originalTime).Duration() < new TimeSpan(0, 0, 5)); // Just test the rest of the streamContext properties here. IDictionary<string, string> testMap = new Dictionary<string, string>(); streamContext = new ArchiveFileStreamContext(cabName, dirB, testMap); Assert.AreSame(testMap, streamContext.Files); Assert.IsFalse(streamContext.EnableOffsetOpen); streamContext.EnableOffsetOpen = true; Assert.IsTrue(streamContext.EnableOffsetOpen); streamContext = new ArchiveFileStreamContext(cabName, ".", testMap); Assert.AreEqual<string>(".", streamContext.Directory); string[] testArchiveFiles = new string[] { cabName }; streamContext = new ArchiveFileStreamContext(testArchiveFiles, ".", testMap); Assert.AreSame(testArchiveFiles, streamContext.ArchiveFiles); } }
public void CabExtractorExtract() { int txtSize = 40960; CabInfo cabInfo = new CabInfo("test.cab"); CompressionTestUtil.GenerateRandomFile("test0.txt", 0, txtSize); CompressionTestUtil.GenerateRandomFile("test1.txt", 1, txtSize); cabInfo.PackFiles(null, new string[] { "test0.txt", "test1.txt" }, null); using (CabEngine cabEngine = new CabEngine()) { using (Stream cabStream = File.OpenRead("test.cab")) { using (Stream exStream = cabEngine.Unpack(cabStream, "test0.txt")) { string str = new StreamReader(exStream).ReadToEnd(); string expected = new StreamReader("test0.txt").ReadToEnd(); Assert.AreEqual<string>(expected, str); } cabStream.Seek(0, SeekOrigin.Begin); using (Stream exStream = cabEngine.Unpack(cabStream, "test1.txt")) { string str = new StreamReader(exStream).ReadToEnd(); string expected = new StreamReader("test1.txt").ReadToEnd(); Assert.AreEqual<string>(expected, str); } } using (Stream txtStream = File.OpenRead("test0.txt")) { Exception caughtEx = null; try { cabEngine.Unpack(txtStream, "test0.txt"); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(CabException)); Assert.AreEqual<int>(2, ((CabException) caughtEx).Error); Assert.AreEqual<int>(0, ((CabException) caughtEx).ErrorCode); Assert.AreEqual<string>("Cabinet file does not have the correct format.", caughtEx.Message); } } }
public void CabExtractorGetFiles() { IList<ArchiveFileInfo> fileInfo; CabInfo cabInfo = new CabInfo("testgetfiles.cab"); int txtSize = 10240; CompressionTestUtil.GenerateRandomFile("testgetfiles0.txt", 0, txtSize); CompressionTestUtil.GenerateRandomFile("testgetfiles1.txt", 1, txtSize); cabInfo.PackFiles(null, new string[] { "testgetfiles0.txt", "testgetfiles1.txt" }, null); using (CabEngine cabEngine = new CabEngine()) { IList<string> files; using (Stream cabStream = File.OpenRead("testgetfiles.cab")) { files = cabEngine.GetFiles(cabStream); } Assert.IsNotNull(files); Assert.AreEqual<int>(2, files.Count); Assert.AreEqual<string>("testgetfiles0.txt", files[0]); Assert.AreEqual<string>("testgetfiles1.txt", files[1]); using (Stream cabStream = File.OpenRead("testgetfiles.cab")) { files = cabEngine.GetFiles(new ArchiveFileStreamContext("testgetfiles.cab"), null); } Assert.IsNotNull(files); Assert.AreEqual<int>(2, files.Count); Assert.AreEqual<string>("testgetfiles0.txt", files[0]); Assert.AreEqual<string>("testgetfiles1.txt", files[1]); using (Stream cabStream = File.OpenRead("testgetfiles.cab")) { fileInfo = cabEngine.GetFileInfo(cabStream); } Assert.IsNotNull(fileInfo); Assert.AreEqual<int>(2, fileInfo.Count); Assert.AreEqual<string>("testgetfiles0.txt", fileInfo[0].Name); Assert.AreEqual<string>("testgetfiles1.txt", fileInfo[1].Name); using (Stream cabStream = File.OpenRead("testgetfiles.cab")) { fileInfo = cabEngine.GetFileInfo(new ArchiveFileStreamContext("testgetfiles.cab"), null); } Assert.IsNotNull(fileInfo); Assert.AreEqual<int>(2, fileInfo.Count); Assert.AreEqual<string>("testgetfiles0.txt", fileInfo[0].Name); Assert.AreEqual<string>("testgetfiles1.txt", fileInfo[1].Name); } fileInfo = this.RunCabinetPackUnpack(15, 20 * 1024, 1 * 1024, 130 * 1024); Assert.IsNotNull(fileInfo); Assert.AreEqual<int>(15, fileInfo.Count); for (int i = 0; i < fileInfo.Count; i++) { Assert.IsNull(fileInfo[i].Archive); Assert.AreEqual<string>(TEST_FILENAME_PREFIX + i + ".txt", fileInfo[i].Name); Assert.IsTrue(DateTime.Now - fileInfo[i].LastWriteTime < new TimeSpan(0, 1, 0)); } }
public void CabExtractorIsCabinet() { int txtSize = 10240; CompressionTestUtil.GenerateRandomFile("test.txt", 0, txtSize); new CabInfo("test.cab").PackFiles(null, new string[] { "test.txt" }, null); using (CabEngine cabEngine = new CabEngine()) { bool isCab; using (Stream fileStream = File.OpenRead("test.txt")) { isCab = cabEngine.IsArchive(fileStream); } Assert.IsFalse(isCab); using (Stream cabStream = File.OpenRead("test.cab")) { isCab = cabEngine.IsArchive(cabStream); } Assert.IsTrue(isCab); using (Stream cabStream = File.OpenRead("test.cab")) { using (Stream fileStream = new FileStream("test.txt", FileMode.Open, FileAccess.ReadWrite)) { fileStream.Seek(0, SeekOrigin.End); byte[] buf = new byte[1024]; int count; while ((count = cabStream.Read(buf, 0, buf.Length)) > 0) { fileStream.Write(buf, 0, count); } fileStream.Seek(0, SeekOrigin.Begin); isCab = cabEngine.IsArchive(fileStream); } } Assert.IsFalse(isCab); using (Stream fileStream = new FileStream("test.txt", FileMode.Open, FileAccess.ReadWrite)) { fileStream.Write(new byte[] { (byte) 'M', (byte) 'S', (byte) 'C', (byte) 'F' }, 0, 4); fileStream.Seek(0, SeekOrigin.Begin); isCab = cabEngine.IsArchive(fileStream); } Assert.IsFalse(isCab); } }
public void CabEngineNoTempFileTest() { int txtSize = 10240; CompressionTestUtil.GenerateRandomFile("testnotemp.txt", 0, txtSize); ArchiveFileStreamContext streamContext = new ArchiveFileStreamContext("testnotemp.cab", null, null); using (CabEngine cabEngine = new CabEngine()) { cabEngine.UseTempFiles = false; cabEngine.Pack(streamContext, new string[] { "testnotemp.txt" }); } new CabInfo("testnotemp.cab").UnpackFile("testnotemp.txt", "testnotemp2.txt"); Assert.AreEqual(txtSize, new FileInfo("testnotemp2.txt").Length); }
private IList<ArchiveFileInfo> RunCabinetPackUnpack(int fileCount, long fileSize, long maxFolderSize, long maxArchiveSize, CompressionLevel compLevel) { Console.WriteLine("Creating cabinet with {0} files of size {1}", fileCount, fileSize); Console.WriteLine("MaxFolderSize={0}, MaxArchiveSize={1}, CompressionLevel={2}", maxFolderSize, maxArchiveSize, compLevel); string dirA = String.Format("{0}-{1}-A", fileCount, fileSize); if (Directory.Exists(dirA)) Directory.Delete(dirA, true); Directory.CreateDirectory(dirA); string dirB = String.Format("{0}-{1}-B", fileCount, fileSize); if (Directory.Exists(dirB)) Directory.Delete(dirB, true); Directory.CreateDirectory(dirB); string[] files = new string[fileCount]; for (int iFile = 0; iFile < fileCount; iFile++) { files[iFile] = TEST_FILENAME_PREFIX + iFile + ".txt"; CompressionTestUtil.GenerateRandomFile(Path.Combine(dirA, files[iFile]), iFile, fileSize); } string[] archiveNames = new string[100]; for (int i = 0; i < archiveNames.Length; i++) { archiveNames[i] = String.Format("{0}-{1}{2}{3}.cab", fileCount, fileSize, (i == 0 ? "" : "-"), (i == 0 ? "" : i.ToString())); } string progressTextFile = String.Format("progress_{0}-{1}.txt", fileCount, fileSize); CompressionTestUtil testUtil = new CompressionTestUtil(progressTextFile); IList<ArchiveFileInfo> fileInfo; using (CabEngine cabEngine = new CabEngine()) { cabEngine.CompressionLevel = compLevel; File.AppendAllText(progressTextFile, "\r\n\r\n====================================================\r\nCREATE\r\n\r\n"); cabEngine.Progress += testUtil.PrintArchiveProgress; OptionStreamContext streamContext = new OptionStreamContext(archiveNames, dirA, null); if (maxFolderSize == 1) { streamContext.OptionHandler = delegate(string optionName, object[] parameters) { if (optionName == "nextFolder") return true; return null; }; } else if (maxFolderSize > 1) { streamContext.OptionHandler = delegate(string optionName, object[] parameters) { if (optionName == "maxFolderSize") return maxFolderSize; return null; }; } cabEngine.Pack(streamContext, files, maxArchiveSize); IList<string> createdArchiveNames = new List<string>(archiveNames.Length); for (int i = 0; i < archiveNames.Length; i++) { if (File.Exists(archiveNames[i])) { createdArchiveNames.Add(archiveNames[i]); } else { break; } } Console.WriteLine("Listing cabinet with {0} files of size {1}", fileCount, fileSize); File.AppendAllText(progressTextFile, "\r\n\r\nLIST\r\n\r\n"); fileInfo = cabEngine.GetFileInfo( new ArchiveFileStreamContext(createdArchiveNames, null, null), null); Assert.AreEqual<int>(fileCount, fileInfo.Count); if (fileCount > 0) { int folders = ((CabFileInfo) fileInfo[fileInfo.Count - 1]).CabinetFolderNumber + 1; if (maxFolderSize == 1) { Assert.AreEqual<int>(fileCount, folders); } } Console.WriteLine("Extracting cabinet with {0} files of size {1}", fileCount, fileSize); File.AppendAllText(progressTextFile, "\r\n\r\nEXTRACT\r\n\r\n"); cabEngine.Unpack(new ArchiveFileStreamContext(createdArchiveNames, dirB, null), null); } bool directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB); Assert.IsTrue(directoryMatch, "Testing whether cabinet output directory matches input directory."); return fileInfo; }
public void CabEngineNullParams() { string[] testFiles = new string[] { "test.txt" }; ArchiveFileStreamContext streamContext = new ArchiveFileStreamContext("test.cab", null, null); using (CabEngine cabEngine = new CabEngine()) { cabEngine.CompressionLevel = CompressionLevel.None; CompressionTestUtil.TestCompressionEngineNullParams( cabEngine, streamContext, testFiles); } }
public void CabExtractorFindOffset() { int txtSize = 10240; CompressionTestUtil.GenerateRandomFile("test.txt", 0, txtSize); new CabInfo("test.cab").PackFiles(null, new string[] { "test.txt" }, null); using (CabEngine cabEngine = new CabEngine()) { long offset; using (Stream fileStream = File.OpenRead("test.txt")) { offset = cabEngine.FindArchiveOffset(fileStream); } Assert.AreEqual<long>(-1, offset); using (Stream cabStream = File.OpenRead("test.cab")) { using (Stream fileStream = new FileStream("test.txt", FileMode.Open, FileAccess.ReadWrite)) { fileStream.Seek(0, SeekOrigin.End); byte[] buf = new byte[1024]; int count; while ((count = cabStream.Read(buf, 0, buf.Length)) > 0) { fileStream.Write(buf, 0, count); } fileStream.Seek(0, SeekOrigin.Begin); offset = cabEngine.FindArchiveOffset(fileStream); } } Assert.AreEqual<long>(txtSize, offset); } }