************************************************************************ * GZipCompressString **************************************** *** Function: Compresses a string using GZip *** Assume: Requires ZLIB1.DLL *** Pass: *** Return: ************************************************************************ FUNCTION GZipCompressString(lcString,lnCompressionLevel) LOCAL lcOutput, lcOutFile,lcInFile, lnHandle *** 1 - 9 IF EMPTY(lnCompressionLevel) lnCompressionLevel = -1 && Default ENDIF *** Must write to files lcOutFile = SYS(2023) + SYS(2015) + TRANS(Application.ProcessId) + ".gz" lcInFile = lcOutFile + ".in" *** Failure to write the file IF !FILE2VAR(lcInFile,lcString) RETURN "" ENDIF IF !VARTYPE(_GZipLoaded) = "L" GzipLibraries() ENDIF TRY lnHandle = gzopen(lcOutFile,"wb") IF (lnHandle < 0) RETURN "" ENDIF *** Set the compression level gzsetparams(lnHandle,lnCompressionLevel,0) gzwrite(lnHandle,lcString,LEN(lcString)) gzclose(lnHandle) CATCH IF lnHandle > -1 gzclose(lnHandle) ENDIF ENDTRY lcOutput = FILETOSTR(lcOutFile) ERASE (lcOutFile) ERASE (lcInFile) RETURN lcOutput ************************************************************************ * GZipUncompressString **************************************** *** Function: Uncompresses a GZip string *** Assume: *** Pass: lcCompressed - Compressed String *** llIsFile - if .T. lcCompressed is a file *** Return: decompressed string ************************************************************************ FUNCTION GZipUncompressString(lcCompressed,llIsFile) LOCAL lcInFile, lcOutput, lnHandle IF llIsFile *** Use parameter file name as input lcInFile = lcCompressed ELSE lcInFile = ADDBS(SYS(2023)) + SYS(2015) + TRANSFORM(Application.ProcessId) + ".gz" *** Copy file to disk and use as input FILE2VAR(lcInFile,lcCompressed) ENDIF IF !VARTYPE(_GZipLoaded) = "L" GzipLibraries() ENDIF lcOutput = "" TRY lnHandle = gzopen(lcInFile,"rb") IF (lnHandle < 1) RETURN "" ENDIF lcOutput = "" DO WHILE .T. lcBuffer = SPACE(65535) lnResult = gzread(lnHandle,@lcBuffer,LEN(lcBuffer)) IF lnResult < 1 EXIT ENDIF lcOutput = lcOutput + LEFT(lcBuffer,lnResult) ENDDO CATCH * Nothing FINALLY IF lnHandle > 0 gzclose(lnHandle) ENDIF ERASE(lcInFile) ENDTRY RETURN lcOutput * eof GZipUncompressString ************************************************************************ * GzipLibraries **************************************** *** Function: *** Assume: *** Pass: *** Return: ************************************************************************ FUNCTION GzipLibraries() PUBLIC _GZipLoaded _GZipLoaded=.T. * Opens file for writing DECLARE LONG gzopen IN zlib1.dll ; STRING @ zFile ,; STRING @ zMode * Writes data from a compressed file - gzip DECLARE LONG gzwrite IN zlib1.dll ; LONG FILE ,; STRING @ uncompr,; LONG uncomprLen *** Set options on the compression DECLARE LONG gzsetparams IN zlib1.DLL ; LONG gzFile,; INTEGER LEVEL,; INTEGER strategy DECLARE LONG gzread IN zlib1.dll ; LONG gzFile,; STRING @ buf,; LONG LEN * Closes the file DECLARE LONG gzclose IN zlib1.dll ; LONG FILE RETURNIf you use Web Connection, IPStuff or Client Tools wwAPI.prg contains these standalone functions.