0

I'm stuck integrating data produced in VB.net to a new php application.

I got two function for compress and uncompress data (eg. image):

''' <summary>
''' Compress data into zip
''' </summary>
''' <param name="bin">input byte array</param>
''' <returns>output byte array</returns>
''' <remarks></remarks>
Public Shared Function CompressData(ByVal bin() As Byte) As Byte()
    Dim buffer(1024 * 4 - 1) As Byte

    Dim mout As New System.IO.MemoryStream()
    Using zout As New ICSharpCode.SharpZipLib.Zip.ZipOutputStream(mout)
        zout.SetLevel(9)
        Using min As New System.IO.MemoryStream(bin)
            Dim zentry As New ICSharpCode.SharpZipLib.Zip.ZipEntry(String.Empty)
            zout.PutNextEntry(zentry)
            ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(min, zout, buffer)
        End Using
        zout.Finish()
    End Using

    Return mout.ToArray()
End Function

''' <summary>
''' Uncompress data from zip
''' </summary>
''' <param name="bin">input byte array</param>
''' <returns>output byte array</returns>
''' <remarks></remarks>
Public Shared Function DecompressData(ByVal bin() As Byte) As Byte()
    Dim buffer(1024 * 4 - 1) As Byte

    Dim mout As New System.IO.MemoryStream()

    Using zin As New ICSharpCode.SharpZipLib.Zip.ZipInputStream(New System.IO.MemoryStream(bin))
        Dim zentry As ICSharpCode.SharpZipLib.Zip.ZipEntry = zin.GetNextEntry()
        Do While zentry IsNot Nothing
            If zentry.IsFile Then
                ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(zin, mout, buffer)
                Exit Do
            End If
        Loop
    End Using

    Return mout.ToArray()
End Function

In the database I have the base64 encoded text produced by the function CompressData and I'm able to read and base64_decode the text.

Any idea for get back the original file in PHP?

Cheers!

Tiziano
  • 23
  • 6
  • Are you asking how to [unzip a zip archive in PHP](https://stackoverflow.com/questions/8889025/unzip-a-file-with-php)? – Andrew Morton Feb 19 '19 at 16:03
  • @AndrewMorton No my problem is a little bit different. The previous developer decided to save the image inside the db through the "compress data" function (see visual basic code in the post). He only pass the byte contents of the image to the function, encodes the results in base64, save the result inside the database. Now in PHP I want to get back the original byte contents but I don't know how to reproduce the "DecompressData" function – Tiziano Feb 25 '19 at 08:02
  • My knowledge of PHP is about zero, but if you had a way of reproducing the memory stream aspect, would that make it easier? [Manipulate an Archive in memory with PHP (without creating a temporary file on disk)](https://stackoverflow.com/q/1189019/1115360). – Andrew Morton Feb 25 '19 at 09:29

0 Answers0