ZLIB.DLL中BLOB变量压缩与解压函数的使用方法

来源:互联网 发布:北京网站制作优化 编辑:程序博客网 时间:2024/05/12 16:17

最近碰上不少朋友问变量压缩的问题,这里整理一下。

函数申明: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 lulSourceLenlong llRCulong   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 llRCstring ls_srclong 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 -1END IF/////////////////////

lulSourceLen = Len( ablSource )

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

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

ablDestination = BlobMid( ablDestination, 1, aulDestinationLength )

RETURN llRC 

原创粉丝点击