Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET reproducable FileSystemInternalException

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #20492 |

    We have an app that zips data from files, all in memory, and stores it in a database.  It will later unzip the data from the database.  We have a certain input that zips fine, and unzips fine.  However, once the unzip is performed once, subsequent zip operations fail with FileSystemInternalException.  This is with the latest release of the 5.1 components.  The full project is at http://staging.bookingbuilder.com/seth/XceedZipTester2.zip

     To see the issue, zip zipit, then unzipit then zipit again.    The relevant source is below as well.

     

    Thank you.

    Seth 

     

    Public Class Form1

        Private _zippedString As String = “”

        Private _unzippedString As String = “”

        Private Sub ZipIt()

            Dim bytes As Byte()

            ‘bytes = System.IO.File.ReadAllBytes(“c:\testoutput.txt”)

            Dim data As String = “one:2012:03:13 08:47:40.4176one:2012:03:13 08:47:48.5180one:2012:03:13 08:48:07.6921”

            Dim enc As New System.Text.UTF8Encoding

            bytes = enc.GetBytes(data)

            Dim zip As New XceedZip

            _zippedString = zip.ZipToBase64EncodedString(bytes)

        End Sub

        Private Sub UnZipIt()

            If String.IsNullOrEmpty(_zippedString) Then Exit Sub

            Dim zip As New XceedZip

            _unzippedString = zip.UnzipToString(_zippedString)

        End Sub

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            ZipIt()

        End Sub

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

            UnZipIt()

        End Sub

    End Class

    Public Function ZipToByteArray(ByVal data() As Byte, ByVal encryptionPassword As String, ByVal fileNameInZipFile As String) As Byte()

            Dim ZipFileInMemory As New Xceed.FileSystem.MemoryFile(“RAM_File”, “zipfile.zip”)

            If String.IsNullOrEmpty(fileNameInZipFile) Then fileNameInZipFile = “InternalFileNameOnly”

            Dim FileToBeZipped As New Xceed.FileSystem.MemoryFile(“RAM_File”, fileNameInZipFile)

            FileToBeZipped.Create()

            ‘ write the data to the file to be zipped

            Dim str As System.IO.Stream = FileToBeZipped.OpenWrite(True)

            str.Write(data, 0, data.Length)

            str.Close()

            ‘ now create the zip archive (zip file)

            Dim zipArchive As New ZipArchive(ZipFileInMemory)

            zipArchive.TempFolder = New MemoryFolder(“ram:\”)

            zipArchive.DefaultCompressionLevel = Xceed.Compression.CompressionLevel.Highest

            zipArchive.DefaultCompressionMethod = Xceed.Compression.CompressionMethod.LZMA

            If Not String.IsNullOrEmpty(encryptionPassword) Then

                zipArchive.DefaultEncryptionMethod = EncryptionMethod.WinZipAes

                zipArchive.DefaultEncryptionPassword = encryptionPassword

            End If

            ‘ copy the file to be zipped to the zip archive

            FileToBeZipped.CopyTo(zipArchive, True)

            ‘ to write the zip file to a physical file

            ‘memZipFile.CopyTo(New DiskFile(“c:\bbutilty.zip”), True)

            ‘ now let’s get the memory zip file into a byte array

            str = ZipFileInMemory.OpenRead()

            Dim BytesToReturn() As Byte

            ReDim BytesToReturn(CInt(str.Length))

            str.Read(BytesToReturn, 0, CInt(str.Length))

            str.Close()

            ‘ now write the byte array to a file if needed

            ‘System.IO.File.WriteAllBytes(“c:\bbutility2.zip”, abytZipFile)

            FileToBeZipped.Delete()

            ZipFileInMemory.Delete()

            zipArchive = Nothing

            Return BytesToReturn

        End Function

     

    Public Function UnzipToByteArray(ByVal zippedData() As Byte, ByVal encryptionPassword As String) As Byte()

            ‘ unzips the first file in a zip archive and returns it as a string

            Try

                Dim ZipFileInMemory As New Xceed.FileSystem.MemoryFile(“RAM_File”, “zipfile.zip”)

                ZipFileInMemory.Create()

                ‘ write the data to the file to be zipped

                Dim str As System.IO.Stream = ZipFileInMemory.OpenWrite(True)

                str.Write(zippedData, 0, zippedData.Length)

                str.Close()

                Dim zip As New ZipArchive(ZipFileInMemory)

                If Not String.IsNullOrEmpty(encryptionPassword) Then

                    zip.DefaultEncryptionMethod = EncryptionMethod.WinZipAes

                    zip.DefaultDecryptionPassword = encryptionPassword

                End If

                For Each f As AbstractFile In zip.GetFiles(True)

                    ‘ we don’t know the length, so we’ll write it into a new stream, then move that into a byte array

                    Dim buffer(1000) As Byte

                    Dim unzippedStream As New System.IO.MemoryStream(1000)

                    Dim zippedStream As System.IO.Stream = f.OpenRead

                    Dim bytesInBuffer As Integer = zippedStream.Read(buffer, 0, buffer.Length)

                    unzippedStream.Write(buffer, 0, bytesInBuffer)

                    Do While bytesInBuffer > 0

                        bytesInBuffer = zippedStream.Read(buffer, 0, buffer.Length)

                        ‘Debug.Print(CStr(bytesInBuffer))

                        unzippedStream.Write(buffer, 0, bytesInBuffer)

                    Loop

                    ‘ now that we have a seekable stream, we can easily write it to a byte array

                    unzippedStream.Flush()

                    Dim unzippedBytes() As Byte = unzippedStream.GetBuffer() ‘ this returns the number of bytes expanded to the buffer size

                    ReDim Preserve unzippedBytes(CInt(unzippedStream.Length – 1)) ‘ so let’s trim it to the actual size

                    Return unzippedBytes

                    Exit For

                Next

            Catch ex As Exception

            End Try

            Return Nothing

        End Function 

    Imported from legacy forums. Posted by Seth (had 901 views)

    User (Old forums)
    Member
    Post count: 23064

    More information:  It seems to have this issue regardless of the input.  Perhaps I’m not clearing something?  We’ve used xceed zip for a long time and never had an issue, but our app has not previously had to unzip then zip.

    Our goal is to get a standard zip file in memory and stored in a database.  We need to be able to zip and unzip completely in memory, and our code is based upon your examples. 

    Thank you.

     Seth 

    Imported from legacy forums. Posted by Seth (had 891 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.