Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Compress a string or a file.
Message
From
27/06/2003 05:30:30
Dorin Vasilescu
ALL Trans Romania
Arad, Romania
 
 
To
27/06/2003 04:56:07
Dino Liberale
Ministero Lavori Pubblici
Trieste, Italy
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00804572
Message ID:
00804573
Views:
32
First, get zLib 32 bit DLL from http://www.winimage.com/zLibDll/zlib114dll.zip and place it into your app's folder.

Next, use the following code (I don't remember exactly from where it is):
lcCompressedDoc = zLib("CompressIt", FileToStr("mydoc.doc"))
lcUncompressedDoc = zLib("UnCompressIt", lcCompressedDoc)
StrToFile( lcUncompressedDoc, "mydoc.out.doc" )
PROCEDURE zLib
PARAMETER cFunc, cStr
  DO CASE
    CASE upper(cFunc)='COMPRESS'
      RETURN CompressIt(cStr)
    CASE upper(cFunc)='UNCOMPRESS'
      RETURN UnCompressIt(cStr)
  ENDCASE
RETURN ''

Function CompressIt( InFile )
DECLARE INTEGER compress IN zlib.dll AS zlibCompress ;
  STRING @ dest, INTEGER @ destLen, ;
  STRING src, INTEGER srcLen
LOCAL lnSize, lcBuff, lnFinalSize
lnSize = len(InFile)
lcBuff      = space( len(InFile)*1.2 )
lnFinalSize = len(lcBuff)
Res = zlibCompress( @lcBuff, @lnFinalSize, InFile, lnSize )
If Res=0 && Success
  RETURN PadL( alltrim(str(lnSize)), 15, '0' ) + Left( lcBuff, lnFinalSize ) 
endif
RETURN ''

FUNCTION UnCompressIt( zLibFile )
DECLARE INTEGER uncompress IN zlib.dll AS zlibUnCompress ;
  STRING @ dest, INTEGER @ destLen, ;
  STRING src, INTEGER srcLen
LOCAL lnSize, lcBuff, lnFinalSize
lnSize = len(zLibFile)
lnFinalSize = Val( Left( zLibFile, 15 ) )
lcBuff      = space( lnFinalSize )
zLibFile    = SubStr( zLibFile, 16 )
Res = zlibUnCompress( @lcBuff, @lnFinalSize, zLibFile, lnSize )
If Res=0 && Success
  RETURN lcBuff
endif
RETURN ''
>I save word documents in a database in Memo (binary) field by filetostr() and strtofile() to retrive it.
>Now db dimension grow.
>Is there a way first to compress file ? (like zip it)
>Next I can aquire it by filetostr().
>To retrive document the inverse process.
>
>Thanks,
>
>Dino
Previous
Reply
Map
View

Click here to load this message in the networking platform