1

Is it possible to write the extraction output from SevenZipSharp to file on the fly rather than to memory and then to file?

The reason I am writing to a stream rather than directly to a file is to check a Byte at a specific location (to determine the version of the file being extracted) I would like to get this value as soon as possible, rather than after the file is extracted.

The sample code works but is extremely slow, I cannot work out a method to write the stream within the events. Dim ms As New 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
madlan
  • 1,387
  • 10
  • 34
  • 63

0 Answers0