Thank you Idle.
I solved the problem already.
It was the Str() around the "gzwrite(*Filehandle, *InBuffer, 10)" command which caused the error.
My current testcode looks like shown below.
But now there is another problem. If I compile this code with PB 4.31 then all runs without error. But if I compile it with another, higer PB Version I'll get this compiler error:
And I have no idea why.
By the way @PB user at Mac and Linux: Would you guys please test this code on Mac and Linux?
I plan to write a multiplatform application using this zLib functions and I cannot test this for myself on Mac and Linux due to lack of this systems. Thank you very much.
This code compress the string sTextIn into a file in your systems temp directory, reopen this file and decompress the text into sTextOut and print out this string in the Debugwindow of PB. So please run it with debugger enabled.
Code: Select all
; PB 4.31 code
EnableExplicit
; I don't know how to convert this C structure to PB whether it is even necessary (see below -> *Filehandle.l works also)
; zlib.h
; struct gzFile_s {
; unsigned have;
; unsigned char *Next;
; z_off64_t pos;
; };
; zconf.h
; # Define z_off64_t z_off_t
; # Define z_off_t long
; Will be created in your system temp directory
#Tmpfile = "Tempfile.txt"
Structure gzFile_s
have.i
Next.i
pos.i
EndStructure
Global sOutFile.s, sTextIn.s, sTextOut.s
Global *InBuffer
Global *Filehandle.gzFile_s ; but works also with *Filehandle.l - what's right and what's wrong? :-/
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
#ZLIB_LIB$ = #PB_Compiler_Home + "purelibraries/linux/libraries/zlib.a"
CompilerCase #PB_OS_MacOS
#ZLIB_LIB$ = "/usr/lib/libz.dylib"
CompilerCase #PB_OS_Windows
#ZLIB_LIB$ = "zlib.lib"
CompilerDefault
CompilerError "OS is not supported!"
End
CompilerEndSelect
ImportC #ZLIB_LIB$
gzopen.i(a.s, b.s) As "_gzopen"
gzclose.i(a.l) As "_gzclose"
gzread.i(a.l, b.l, c.l) As "_gzread"
gzwrite.i(a.l, b.l, c.l) As "_gzwrite"
EndImport
sTextIn = "01234567890123456789 sdmöoivgsmöoijgvmeug,04i5e0c04u049cvu04u04u,v04u,v04v,uh04vu,40"
sTextOut = Space(1024)
*InBuffer = @sTextIn
*Filehandle = gzopen(GetTemporaryDirectory() + #Tmpfile, "wb9")
If *Filehandle <> 0
Debug gzwrite(*Filehandle, *InBuffer, Len(sTextIn))
gzclose(*Filehandle)
EndIf
*InBuffer = @sTextOut
*Filehandle = gzopen(GetTemporaryDirectory() + #Tmpfile, "rb")
If *Filehandle <> 0
Debug gzread (*Filehandle, *InBuffer, Len(sTextIn));
gzclose(*Filehandle)
Debug sTextOut
EndIf