Attribute VB_Name = "Modcompbyte"
Private Declare Function compress Lib "zlib.dll" (dest As Any, destlen As Any, src As Any, ByVal srclen As Long) As Long
Private Declare Function uncompress Lib "zlib.dll" (dest As Any, destlen As Any, src As Any, ByVal srclen As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Global zort As String
Public Function CompressByte(ByteArray() As Byte) As Boolean

  Dim BufferSize As Long
  Dim TempBuffer() As Byte
  
  'Create a buffer to hold the compressed data
  BufferSize = UBound(ByteArray) + 1
  BufferSize = BufferSize + (BufferSize * 0.01) + 12
  ReDim TempBuffer(BufferSize)

  'Compress byte array (data)
  CompressByte = (compress(TempBuffer(0), BufferSize, ByteArray(0), UBound(ByteArray) + 1) = 0)

  'Add the size of the original data
  Call CopyMemory(ByteArray(0), CLng(UBound(ByteArray) + 1), 4)
  
  'Remove redundant data
  ReDim Preserve ByteArray(0 To BufferSize + 3)
  Call CopyMemory(ByteArray(4), TempBuffer(0), BufferSize)
  

End Function
Public Function DecompressByte(TheData() As Byte)

  Dim OrigLen As Long
  Dim BufferSize As Long
  Dim TempBuffer() As Byte
  'Get the original size
  Call CopyMemory(OrigLen, TheData(0), 4)
  
  'Create a buffer to hold the uncompressed data
  BufferSize = OrigLen
  BufferSize = BufferSize + (BufferSize * 0.01) + 12
  ReDim TempBuffer(BufferSize)

  'Decompress data
  Call uncompress(TempBuffer(0), BufferSize, TheData(4), UBound(TheData) - 4 + 1)

  'Remove redundant data
  ReDim Preserve TheData(0 To BufferSize - 1)
  CopyMemory TheData(0), TempBuffer(0), BufferSize
  'rnr() = TheData()

End Function


