Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Read a zip file from byte array

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

    Hi,

    I have created a zip file and converted it to a byte array to be sent across to another component. In that component, I have to read it back from byte array and convert it to either a zip file or extract contents of the zip file to a local folder. How can i read the zip file from the byte array. Please help with a code snippet.

    Thanks.

     

    Private Shared Function ZipSelectedFiles(ByVal list As Dictionary(Of Integer, String)) As Byte()

    Dim file As DiskFile

    Dim memFile As New MemoryFile(“RAM_File”, “lasfiles.zip”)

    Dim zip As New ZipArchive(memFile)

    Dim zipBytes() As Byte

    For Each kvp As KeyValuePair(Of Integer, String) In list

    file =

    New DiskFile(kvp.Value)

    file.CopyTo(zip,

    False)

    Next kvp

    Dim zipMemStream As New MemoryStream()

    Dim s As Stream = memFile.OpenRead()

    Dim buffer(1024) As Byte

    Dim bytesRead As Integer

    Do

    bytesRead = s.Read(buffer, 0, buffer.Length)

    If bytesRead > 0 Then

    zipMemStream.Write(buffer, 0, bytesRead)

    End If

    Loop Until bytesRead = 0

    s.Close()

    zipBytes = zipMemStream.ToArray()

    zipMemStream.Close()

    Return zipBytes

    End Function

    Imported from legacy forums. Posted by Zaffar (had 2829 views)

    User (Old forums)
    Member
    Post count: 23064

    I need an answer to this question

    Imported from legacy forums. Posted by a (had 440 views)

    User (Old forums)
    Member
    Post count: 23064
     Use an intermediate Xceed StreamFile with your MemoryStream.
     
                byte[] buffer = …;
                using(var stream = new MemoryStream(buffer))
                {
                    var archive = new ZipArchive(new StreamFile(stream))
                    …
                }
     
     

    Imported from legacy forums. Posted by Jason (had 1318 views)

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