是否可以将 SevenZipSharp 的提取输出即时写入文件而不是写入内存然后写入文件?
我写入流而不是直接写入文件的原因是检查特定位置的字节(以确定正在提取的文件的版本)我想尽快获得这个值,而不是在文件被提取。
示例代码有效,但速度极慢,我无法找到在事件中写入流的方法。将 ms 调暗为新的 MemoryStream
Private Sub Test()
Using tmp = New SevenZipExtractor(FILENAME)
AddHandler tmp.Extracting, AddressOf SevenZip_Extracting
AddHandler tmp.ExtractionFinished, AddressOf SevenZip_ExtractionFinished
tmp.ExtractFile(0, ms)
End Using
End Sub
Private Sub SevenZip_Extracting(ByVal sender As Object, ByVal e As ProgressEventArgs)
' Read Bytes at position 3756 (b * 256 + a)
If e.PercentDone = 1 Then
Dim br As BinaryReader = New BinaryReader(ms)
Dim lngStartPos As Long = 3756
br.BaseStream.Seek(lngStartPos, SeekOrigin.Begin)
Dim a As Byte = br.ReadByte()
Dim b As Byte = br.ReadByte()
Console.WriteLine(b * 256 + a)
End If
Using fs As FileStream = File.OpenWrite("C:\Temp\output.tmp")
ms.WriteTo(fs)
End Using
End Sub