Private Declare Function compress2 _
Lib "zlibwapi.dll" (ByVal dest As String, _
destLen As Long, _
ByVal source As String, _
ByVal sourceLen As Long, _
ByVal Level As Long) As Long
Private Declare Function compressBound _
Lib "zlibwapi.dll" (ByVal sourceLen As Long) As Long
Private Declare Function uncompress _
Lib "zlibwapi.dll" (dest As Any, _
destLen As Any, _
src As Any, _
ByVal srcLen As Long) As Long
Private Declare Function uncompressBound _
Lib "zlibwapi.dll" (ByVal sourceLen As Long) As Long
Private Declare Function zuncompressstr _
Lib "zlibwapi.dll" (ByVal dest As String, _
destLen As Long, _
ByVal source As String, _
ByVal sourceLen As Long) As Long
Private Const Z_NO_FLUSH As Long = 0&
Private Const Z_PARTIAL_FLUSH As Long = 1&
Private Const Z_SYNC_FLUSH As Long = 2&
Private Const Z_FULL_FLUSH As Long = 3&
Private Const Z_FINISH As Long = 4&
Private Const Z_BLOCK As Long = 5&
Private Const Z_OK As Long = 0&
Private Const Z_STREAM_END As Long = 1&
Private Const Z_NEED_DICT As Long = 2&
Private Const Z_ERRNO As Long = -1&
Private Const Z_STREAM_ERROR As Long = -2&
Private Const Z_DATA_ERROR As Long = -3&
Private Const Z_MEM_ERROR As Long = -4&
Private Const Z_BUF_ERROR As Long = -5&
Private Const Z_VERSION_ERROR As Long = -6&
Private Const Z_NO_COMPRESSION As Long = 0&
Private Const Z_BEST_SPEED As Long = 1&
Private Const Z_BEST_COMPRESSION As Long = 9&
Private Const Z_DEFAULT_COMPRESSION As Long = -1&
Private Const Z_FILTERED As Long = 1&
Private Const Z_HUFFMAN_ONLY As Long = 2&
Private Const Z_RLE As Long = 3&
Private Const Z_DEFAULT_STRATEGY As Long = 0&
Private Const Z_BINARY As Long = 0&
Private Const Z_ASCII As Long = 1&
Private Const Z_UNKNOWN As Long = 2&
Private Const Z_DEFLATED As Long = 8&
Private Const ZLIB_VERSION As String = "1.2.1"
Public Function Compress(Data As String) As String
Dim Output As String, OutputLength As Long
OutputLength = compressBound(Len(Data))
Output = Space(OutputLength)
Debug.Assert compress2(Output, OutputLength, Data, Len(Data), Z_BEST_COMPRESSION) = Z_OK
Compress = Left$(Output, OutputLength)
End Function
' OrigSize - длина строки до сжатия
Public Function DecompressString(TheString As String, _
OrigSize As Long) As Long
'Allocate string space
Dim CmpSize As Long
Dim TBuff As String
Dim result As Long
TBuff = String(OrigSize + (OrigSize * 0.01) + 12, 0)
CmpSize = Len(TBuff)
'Decompress
result = uncompress(ByVal TBuff, CmpSize, ByVal TheString, Len(TheString))
'Make string the size of the uncompressed string
TheString = Left$(TBuff, CmpSize)
'Reset properties
If result = 0 Then
'CompressedSize = 0
OrigSize = 0
End If
'Return error code (if any)
DecompressString = result
End Function
' сжатие
ДлинаСтрокиДоСжатия = Len(твояСтрока)
будетСжатаястрока = Compress(твояСтрока)
' расжатие
СжатаяСтрока = будетСжатаястрока
DecompressString(СжатаяСтрока, ДлинаСтрокиДоСжатия)
РасжатаяВновьСтрока = СжатаяСтрока
Сейчас этот форум просматривают: SemrushBot и гости: 21