@@ -1602,6 +1602,8 @@ Private Function pvToWinFileName(baBuffer() As Byte, ByVal lCodePage As Long) As
16021602 pvToWinFileName = Join(vSplit, "\" )
16031603End Function
16041604
1605+ #End If ' ImplDecompress
1606+
16051607#If ImplInflate Then
16061608
16071609Public Function InflateBase64 (sText As String , baOutput() As Byte ) As Boolean
@@ -1645,57 +1647,93 @@ EH:
16451647 Resume QH
16461648End Function
16471649
1650+ Public Function DeflateBase64 (baInput() As Byte , sText As String , Optional ByVal Level As Long = 6 ) As Boolean
1651+ Dim baOutput() As Byte
1652+
1653+ DeflateBase64 = Deflate(baInput, baOutput, Level)
1654+ If DeflateBase64 Then
1655+ sText = ToBase64String(baOutput)
1656+ End If
1657+ End Function
1658+
16481659Public Function Deflate (baBuffer() As Byte , baOutput() As Byte , Optional ByVal Level As Long = 6 ) As Boolean
16491660 Const FUNC_NAME As String = "Deflate"
16501661 Dim hCtx As Long
1651- Dim uBuf As UcsZlibBuffersType
1652- Dim lResult As Long
1662+ Dim lOutputPtr As Long
1663+ Dim lOutputSize As Long
16531664
16541665 On Error GoTo EH
1655- hCtx = CallWindowProc(m_uRtbl.CompressInit, VarPtr(m_uRtbl))
1656- If hCtx = 0 Then
1666+ hCtx = DeflateInit()
1667+ If Not DeflateBlob(hCtx, VarPtr(baBuffer(0 )), UBound(baBuffer) + 1 , lOutputPtr, lOutputSize, Level, 1 ) Then
1668+ GoTo QH
1669+ End If
1670+ ReDim baOutput(0 To lOutputSize - 1 ) As Byte
1671+ Call CopyMemory (baOutput(0 ), ByVal lOutputPtr, lOutputSize)
1672+ '--- success
1673+ Deflate = True
1674+ QH:
1675+ On Error Resume Next
1676+ If lOutputPtr <> 0 Then
1677+ Call CoTaskMemFree (lOutputPtr)
1678+ End If
1679+ If hCtx <> 0 Then
1680+ DeflateEnd hCtx
1681+ End If
1682+ Exit Function
1683+ EH:
1684+ pvSetError MODULE_NAME & "." & FUNC_NAME & vbCrLf & Err.Source, Err.Description
1685+ Resume QH
1686+ End Function
1687+
1688+ Public Function DeflateInit () As Long
1689+ DeflateInit = CallWindowProc(m_uRtbl.CompressInit, VarPtr(m_uRtbl))
1690+ If DeflateInit = 0 Then
16571691 Err.Raise vbObjectError, , ERR_INIT_COMPRESSOR
16581692 End If
1693+ End Function
1694+
1695+ Public Function DeflateBlob (ByVal hCtx As Long , ByVal lInputPtr As Long , ByVal lInputSize As Long , lOutputPtr As Long , lOutputSize As Long , Optional ByVal Level As Long = 6 , Optional ByVal Final As Boolean ) As Boolean
1696+ Const FUNC_NAME As String = "DeflateBlob"
1697+ Dim uBuf As UcsZlibBuffersType
1698+ Dim lResult As Long
1699+
1700+ On Error GoTo EH
16591701 uBuf.Greedy = (Level <= 4 )
16601702 uBuf.MaxMatch = At(Array(0 , 2 , 6 , 12 , 24 , 8 , 16 , 32 , 64 , 1000 ), Level)
16611703 uBuf.NiceLen = At(Array(0 , 8 , 10 , 14 , 24 , 30 , 65 , 130 , 200 , 32768 ), Level)
1662- uBuf.InBlock = VarPtr(baBuffer( 0 ))
1663- uBuf.InLen = UBound(baBuffer) + 1
1664- uBuf.Final = 1
1704+ uBuf.InBlock = lInputPtr
1705+ uBuf.InLen = lInputSize
1706+ uBuf.Final = -Final
16651707 lResult = CallWindowProc(m_uRtbl.CompressBlock, hCtx, VarPtr(uBuf))
16661708 If lResult = 0 Or uBuf.OutBlock = 0 Then
16671709 Err.Raise vbObjectError, , ERR_COMPRESSING
16681710 End If
1669- ReDim baOutput(0 To uBuf.OutLen - 1 ) As Byte
1670- Call CopyMemory (baOutput(0 ), ByVal uBuf.OutBlock, uBuf.OutLen)
1711+ '--- commit
1712+ lOutputPtr = uBuf.OutBlock
1713+ lOutputSize = uBuf.OutLen
1714+ uBuf.OutBlock = 0
16711715 '--- success
1672- Deflate = True
1716+ DeflateBlob = True
16731717QH:
16741718 On Error Resume Next
16751719 If uBuf.OutBlock <> 0 Then
16761720 Call CoTaskMemFree (uBuf.OutBlock)
16771721 uBuf.OutBlock = 0
16781722 End If
1679- If hCtx <> 0 Then
1680- Call CallWindowProc (m_uRtbl.CompressCleanup, hCtx)
1681- hCtx = 0
1682- End If
16831723 Exit Function
16841724EH:
16851725 pvSetError MODULE_NAME & "." & FUNC_NAME & vbCrLf & Err.Source, Err.Description
16861726 Resume QH
16871727End Function
16881728
1689- Public Function DeflateBase64 (baInput() As Byte , sText As String , Optional ByVal Level As Long = 6 ) As Boolean
1690- Dim baOutput() As Byte
1691- DeflateBase64 = Deflate(baInput, baOutput, Level )
1692- If DeflateBase64 Then sText = ToBase64String(baOutput)
1693- End Function
1729+ Public Sub DeflateEnd ( ByVal hCtx As Long )
1730+ If hCtx <> 0 Then
1731+ Call CallWindowProc (m_uRtbl.CompressCleanup, hCtx )
1732+ End If
1733+ End Sub
16941734
16951735#End If ' ImplInflate
16961736
1697- #End If ' ImplDecompress
1698-
16991737'= Crypto ================================================================
17001738
17011739#If ImplCrypto Then
0 commit comments