All pastes #382937 Raw Edit

Stuff

public text v1 · immutable
·published 2007-03-06 00:36 UTC
rendered paste body

Public Module zFunctions

    Dim ms As New IO.MemoryStream
    Dim z As New IO.Compression.GZipStream(ms, IO.Compression.CompressionMode.Compress, True)
    Dim zz As IO.Compression.GZipStream
    Public Function Zip(ByVal b() As Byte) As Byte()

        ms.Position = 0

        z.Write(b, 0, b.Length)
        z.Flush()


        Return ms.ToArray()

    End Function

    Public Function UnZip(ByVal b() As Byte) As Byte()

        ms.Position = 0
        zz = New IO.Compression.GZipStream(ms, IO.Compression.CompressionMode.Decompress, True)
        ms.Write(b, 0, b.Length)
        ms.Flush()

        Dim i As Integer
        Do
            If zz.Read(b, i, 1) = 0 Then Exit Do
        Loop
        ReDim Preserve b(i + 1)
        Return b

    End Function

End Module