1. 程式人生 > >ZLIB.DLL中BLOB變數壓縮與解壓函式的使用方法

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