ZLIB.DLL中BLOB變量壓縮與解壓函數的使用方法

最近碰上不少朋友問變量壓縮的問題,這裏整理一下。

函數申明: Function Long compress (Ref blob Destination, Ref ulong DestLen, Ref blob Source, ulong SourceLen ) Library "zlib.dll" Function Long uncompress ( Ref blob Destination, Ref ulong DestLen, Ref blob Sourse, ulong SourceLen ) Library "zlib.dll" 壓縮函數: public function long of_compress (ref blob abldestination, blob ablsource)

ulong lulSourceLen long llRC ulong   luldestinationlength

lulSourceLen = Len( ablSource )

luldestinationlength= (lulSourceLen * 101 / 100) + 12

ablDestination = Blob( Space(luldestinationlength),EncodingANSI! )

llRC = compress( ablDestination, luldestinationlength ,ablSource, lulSourceLen )

ablDestination = BlobMid( ablDestination, 1, luldestinationlength)

ablDestination = BLOB("BUFFER=" + STRING(LEN(ablsource)) + ";", EncodingANSI!) + ablDestination

RETURN llRC

解壓函數: public function long of_uncompress (ref blob abldestination,  blob ablsource)

ulong lulSourceLen, auldestinationlength long llRC string ls_src long ll_pos

ls_src = STRING(ablSource, EncodingANSI!)

ll_pos = POS(ls_src, ";") IF ll_pos > 0 THEN  ls_src = MID(ls_src, 1, ll_pos)  ablSource = BLOBMID(ablSource, ll_pos + 1)  ll_pos = POS(ls_src, "=")  ls_src = MID(ls_src, ll_pos + 1)  auldestinationlength = LONG(MID(ls_src, 1, LEN(ls_src) - 1)) ELSE  RETURN -1 END IF /////////////////////

lulSourceLen = Len( ablSource )

ablDestination = Blob( Space(aulDestinationLength), EncodingANSI!)

llRC = uncompress( ablDestination, aulDestinationLength, ablSource, lulSourceLen )

ablDestination = BlobMid( ablDestination, 1, aulDestinationLength )

RETURN llRC 

發佈了21 篇原創文章 · 獲贊 19 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章