1

I am atempting to open a zip file and extract a password and 256 AES encrypted text file into a stream which I can read WITHOUT puting a copy of the text onto the drive. If I understand what I want to do correctly, using a stream will acomplish that. Im not very experianced with code so Im using example that I found on the DontNetZip site which is bellow. The problem is 2 fold, it throws 2 errors when processing, I was hoping that someone can help with these.

1 the first error occure on the 3rd line - "Using s As CrcCalculatorStream = e1.OpenReader" the error is ' Object reference not set to an instance of an object. ' I have tried declearing and new and still it crashes on that line.

2 the second error is on a line after the loop - "If (s.Crc32 <> e1.Crc32) Then" and the error is a squigly line under s.Crc32 and it sais that Crc32 is not a memeber of CrcCalculatorStream , a similar error under the e1.Crc32 which isnt a member of Ionic.zip.zipEntry

The code is as copied from this link http://cheeso.members.winisp.net/DotNetZipHelp/html/4ef6405c-33ff-a8aa-1731-def3ec5cac24.htm

Can someone help me get through the code to see if I can get the result that Im after , that is to have the content of the text file in a string so that I can read it

PS I have in my real program edited the references to a file and the correct zip name, the only addition is the password.

Thankyou

Using zip As New ZipFile(ZipFileToRead)
Dim e1 As ZipEntry = zip.Item("Elevation.mp3")
Using s As Ionic.Zlib.CrcCalculatorStream = e1.OpenReader(password)
    Dim n As Integer
    Dim buffer As Byte() = New Byte(4096) {}
    Dim totalBytesRead As Integer = 0
    Do
        n = s.Read(buffer, 0, buffer.Length)
        totalBytesRead = (totalBytesRead + n)
    Loop While (n > 0)
    If (s.Crc32 <> e1.Crc32) Then
        Throw New Exception(String.Format("The Zip Entry failed the CRC Check. (0x{0:X8}!=0x{1:X8})", s.Crc32, e1.Crc32))
    End If
    If (totalBytesRead <> e1.UncompressedSize) Then
        Throw New Exception(String.Format("We read an unexpected number of bytes. ({0}!={1})", totalBytesRead, e1.UncompressedSize))
    End If
End Using

End Using

user1500403
  • 551
  • 8
  • 32
  • I have sorted those issues I raised, the object reference exception was due to file without full path .... hence it was null, and the crc32 was changed to Crc and then it was fine. BUT NOW I REALLY NEED HELP. I feel dumb asking this but how do I get the data ?? that is the content of the actual text file! I want to end up with a string that has the content of the file. Is that possible. Thanks – user1500403 Jul 12 '12 at 11:56

1 Answers1

2

I managed to sort that out too , I just though that it might be usefull to somebody.

Dim str as string

                    Using s As Ionic.Crc.CrcCalculatorStream = e.OpenReader(Password)
                        Dim sr As StreamReader = New StreamReader(s)
                        str = sr.ReadToEnd()
                    End Using
user1500403
  • 551
  • 8
  • 32