最近碰上不少朋友问变量压缩的问题,这里整理一下。
函数申明: 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
本文提供了一种使用 zlib 库实现的变量压缩与解压方法。通过定义压缩与解压函数,文章详细介绍了如何对数据进行压缩及解压处理,并确保了数据的完整性和准确性。
3966

被折叠的 条评论
为什么被折叠?



