Code: Select all
; Import-File created by Lib2PBImport
; Libname: zlibstat.lib
; created: 2007/07/09  12:15
Import "zlibstat.lib"
  gzclearerr(a.l) As "_gzclearerr@4"
  gzclose(a.l) As "_gzclose@4"
  gzdopen(a.l,b.l) As "_gzdopen@8"
  gzeof(a.l) As "_gzeof@4"
  gzerror(a.l,b.l) As "_gzerror@8"
  gzflush(a.l,b.l) As "_gzflush@8"
  gzgetc(a.l) As "_gzgetc@4"
  gzgets(a.l,b.l,c.l) As "_gzgets@12"
  gzopen(a.l,b.l) As "_gzopen@8"
  gzprintf() As "_gzprintf"
  gzputc(a.l,b.l) As "_gzputc@8"
  gzputs(a.l,b.l) As "_gzputs@8"
  gzread(a.l,b.l,c.l) As "_gzread@12"
  gzrewind(a.l) As "_gzrewind@4"
  gzseek(a.l,b.l,c.l) As "_gzseek@12"
  gzsetparams(a.l,b.l,c.l) As "_gzsetparams@12"
  gztell(a.l) As "_gztell@4"
  gzungetc(a.l,b.l) As "_gzungetc@8"
  gzwrite(a.l,b.l,c.l) As "_gzwrite@12"
EndImport
;-test gzio, read/write .gz files
Procedure test_gzio()
  Debug "# start gz input / output"
  txt$="another text for testing"
  TESTFILE$="e:\test\gztest.txt.gz" ;- !! change path !!
  Debug "- first output"
  ;-write gz
  fileHdl = gzopen(@TESTFILE$, @"wb9");Type of access permitted "wb" or "rb" + comressionlevel and strategy i.e. "wb9f"
  ;"r"
  ;Opens for reading. If the file does not exist or cannot be found, the fopen call fails.
  ;"w"
  ;Opens an empty file for writing. If the given file exists, its contents are destroyed.
  ;this are the same parameters as for the fopen function in c++
  ;
  ;9 for max compression, 0 for no comression (0 can be good for controlling with an editor what happened).
  ;'f' for filtered data as in "wb6f", 'h' for
  ;Huffman only compression as in "wb1h", Or 'R' For run-length encoding ...
  ;See the description of deflateInit2 in zlib.h  for more information for these parameters
  Debug "fileHdl for write= " + Str(fileHdl)
  zerr=gzputc(fileHdl, Asc("H"))
  Debug "err gzputc " + Str(zerr) + " = " + "Asc('H')" + " = " + Str(Asc("H"))
  len=1
  zerr=gzputs(fileHdl, @"ello |");returns length of the uncompressed string
  Debug "err gzputs " + Str(zerr)
  len + zerr
  xtmp$=txt$ + Str(i) + " "
  zerr=gzwrite(fileHdl, @xtmp$,Len(txt$));returns length of the uncompressed
  Debug "err gzwrite " + Str(zerr)                     ;string if successfull and a zerror if not
  len + zerr
  Debug "Bytes written: " + Str(len)
  zerr=gzclose(fileHdl)
  Debug ""
 
  ;-read gz
  Debug "- then input"
  ;read the uncompressed length
  ;  must not be done, you can allocate a buffer (don´t even have to be much, in my test it worked
  ;                                               with 1 Byte for 20 loops of obove gzwrite !?)
  ;  and do a loop until Zgzread(fileHdl,@Buf$,length-1) returns zero
  ;  look at the gz_uncompress function in minigzip.c from the zlib source this
  ;  demonstrates reading compressed data without knowing the uncompressed length
  If OpenFile(0,TESTFILE$)
    length=Lof(0)
    FileSeek(0,length-4)
    length=ReadLong(0);the length of the uncompressed data is stored in the last 4 bytes
    Debug "length " + Str(length)
    CloseFile(0)
  EndIf
 
  fileHdl = gzopen(@TESTFILE$, @"rb");"rb" for read byte, returns the file handle
  Debug "fileHdl for read= " + Str(fileHdl)
  Buf$=Space(length)
  len=gzread(fileHdl,@Buf$,length)
  Debug PeekS(@Buf$)
  Debug "Bytes read: " + Str(len);if len < 0 then an error occured
 
  zerr=gzclose(fileHdl)
EndProcedureP.S. Where can i get the latest zlib static lib?
Thank you for the help.



