Code: Select all
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
PB_Alignment?.b[?]
CompilerEndIf

Code: Select all
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
PB_Alignment?.b[?]
CompilerEndIf
Code: Select all
Structure Z_STREAM
*next_in.Byte
avail_in.l
total_in.l
*next_out.Byte
avail_out.l
total_out.l
*msg.Byte
*state
zalloc.l
zfree.l
opaque.l
data_type.i
adler.l
reserved.l
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
alignment.l
CompilerEndIf
EndStructure
Code: Select all
Structure Z_STREAM
*next_in.Byte
avail_in.l
total_in.l
*next_out.Byte
avail_out.l
total_out.l
*msg.Byte
*state
zalloc.l
zfree.l
opaque.l
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
PB_Alignment1.b[4]
CompilerEndIf
data_type.i
adler.l
reserved.l
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
PB_Alignment2.b[8]
CompilerEndIf
EndStructure
Yes, still corrupt file.Thunder93 wrote:Are you sure you using exactly the following to work for both PB x64 and x86?
Code: Select all
Structure Z_STREAM *next_in.Byte avail_in.l total_in.l *next_out.Byte avail_out.l total_out.l *msg.Byte *state zalloc.l zfree.l opaque.l CompilerIf #PB_Compiler_Processor = #PB_Processor_x64 PB_Alignment1.b[4] CompilerEndIf data_type.i adler.l reserved.l CompilerIf #PB_Compiler_Processor = #PB_Processor_x64 PB_Alignment2.b[8] CompilerEndIf EndStructure
Here are my tests again... but with older versions of PB w/the above code.
PureBasic v4.60 x64
8e8c5f619da1de67d67480671fc2827c test.dds -- Original
2a0c70c5d54651e0bc59b5bf11ee0697 test.gz -- Created
8e8c5f619da1de67d67480671fc2827c test2.dds -- Extracted
8e8c5f619da1de67d67480671fc2827c test -- Extraction manually via another decompressor
------------
PureBasic v4.41 x86
8e8c5f619da1de67d67480671fc2827c test.dds
2a0c70c5d54651e0bc59b5bf11ee0697 test.gz
8e8c5f619da1de67d67480671fc2827c test2.dds
8e8c5f619da1de67d67480671fc2827c test -- Extraction manually via another decompressor
-------------
Code: Select all
#ENABLE_GZIP = 16
#Z_NULL = 0
#ZLIB_VERSION = "1.2.8"
#Z_FINISH = 4
#Z_DEFAULT_COMPRESSION = -1
#Z_DEFLATED = 8
#MAX_MEM_LEVEL = 9
#Z_DEFAULT_STRATEGY = 0
Structure Z_STREAM
*next_in.Byte
avail_in.l
total_in.l
*next_out.Byte
avail_out.l
total_out.l
*msg.Byte
*state
zalloc.l
zfree.l
opaque.l
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
PB_Alignment1.b[4]
CompilerEndIf
data_type.i
adler.l
reserved.l
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
PB_Alignment2.b[8]
CompilerEndIf
EndStructure
ImportC "zlib.lib"
inflateInit2_(*strm, windowBits.i, Version.s, strm_size)
inflate(*strm, flush.i)
inflateEnd(*strm)
deflateInit2_(*strm, level.i, method.i, windowBits.i, memlevel.i, strategy.i, Version.s, strm_size)
deflateBound(*strm, sourceLen)
deflate(*strm, flush.i)
deflateEnd(*strm)
EndImport
Procedure InflatePayload(*Payload, windowBits.i)
LengthToRead = MemorySize(*Payload)
LengthToWrite = FileSize("test.dds")
*Output = AllocateMemory(LengthToWrite)
strm.Z_STREAM
strm\next_in = *Payload
strm\avail_in = LengthToRead
strm\next_out = *Output
strm\avail_out = LengthToWrite
strm\zalloc = #Z_NULL
strm\zfree = #Z_NULL
strm\opaque = #Z_NULL
inflateInit2_(@strm, windowBits, #ZLIB_VERSION, SizeOf(Z_STREAM))
inflate(@strm, #Z_FINISH)
inflateEnd(@strm)
ProcedureReturn *Output
EndProcedure
Procedure DeflatePayload(*Input, windowBits.i)
LengthToRead = MemorySize(*Input)
strm.Z_STREAM
strm\next_in = *Input
strm\avail_in = LengthToRead
strm\zalloc = #Z_NULL
strm\zfree = #Z_NULL
strm\opaque = #Z_NULL
deflateInit2_(@strm, #Z_DEFAULT_COMPRESSION, #Z_DEFLATED, windowBits, #MAX_MEM_LEVEL, #Z_DEFAULT_STRATEGY, #ZLIB_VERSION, SizeOf(Z_STREAM))
LengthToWrite = deflateBound(@strm, LengthToRead) / 20
*Payload = AllocateMemory(LengthToWrite)
strm\next_out = *Payload
strm\avail_out = LengthToWrite
deflate(@strm, #Z_FINISH)
deflateEnd(@strm)
ProcedureReturn *Payload
EndProcedure
If OpenFile(0, "test.dds")
LengthToRead = FileSize("test.dds")
*Input = AllocateMemory(LengthToRead)
ReadData(0, *Input, LengthToRead)
CloseFile(0)
*Payload = DeflatePayload(*Input, 15 | #ENABLE_GZIP)
If CreateFile(0, "test2.dds")
WriteData(0, *Payload, MemorySize(*Payload))
CloseFile(0)
EndIf
FreeMemory(*Payload)
EndIf
If OpenFile(0, "test2.dds")
LengthToRead = FileSize("test2.dds")
*Payload = AllocateMemory(LengthToRead)
ReadData(0, *Payload, LengthToRead)
CloseFile(0)
*Output = InflatePayload(*Payload, 15 | #ENABLE_GZIP)
If CreateFile(0, "test3.dds")
WriteData(0, *Output, MemorySize(*Output))
CloseFile(0)
EndIf
FreeMemory(*Output)
FreeMemory(*Payload)
EndIf
Code: Select all
*Payload = DeflatePayload(*Input, -15)
Code: Select all
*Output = InflatePayload(*Payload, -15)
JHPJHP wrote:One more thing to try:
Change your code to the following:Code: Select all
*Payload = DeflatePayload(*Input, -15)
Don't worry that the compressed .dds file cannot be opened like a .gz file... this is raw deflate.Code: Select all
*Output = InflatePayload(*Payload, -15)
- the inflated file should be identical to the original
- refer to the documentation: http://zlib.net/manual.html
but I have try with external zlib.dll and the result is the same see the first pageThunder93 wrote:Maybe a PB userlib or a tool extension is messing with your results?