forked from gphilippot/purebasic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZLib.pb
130 lines (105 loc) · 3.38 KB
/
ZLib.pb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
;--------------------------------------------------------------------------------------------
; Copyright (c) Fantaisie Software. All rights reserved.
; Dual licensed under the GPL and Fantaisie Software licenses.
; See LICENSE and LICENSE-FANTAISIE in the project root for license information.
;--------------------------------------------------------------------------------------------
;- zlib import
;
#Z_OK = 0
#Z_STREAM_END = 1
#Z_NEED_DICT = 2
#Z_ERRNO = (-1)
#Z_STREAM_ERROR = (-2)
#Z_DATA_ERROR = (-3)
#Z_MEM_ERROR = (-4)
#Z_BUF_ERROR = (-5)
#Z_VERSION_ERROR = (-6)
#Z_NO_FLUSH = 0
#Z_PARTIAL_FLUSH = 1 ; /* will be removed, use Z_SYNC_FLUSH instead */
#Z_SYNC_FLUSH = 2
#Z_FULL_FLUSH = 3
#Z_FINISH = 4
#Z_BLOCK = 5
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64 And #PB_Compiler_OS <> #PB_OS_Windows
; On Linux x64, a long is 8 byte (unlike Windows x64)
;
Structure z_stream
*next_in.BYTE
avail_in.l
pad.l
total_in.i ; uLong
*next_out.BYTE
avail_out.l
pad2.l
total_out.i ; uLong
*msg.BYTE
*state
zalloc.i
zfree.i
opaque.i
data_type.l
pad3.l
adler.i ; uLong
reserved.i ; uLong
EndStructure
CompilerElse
Structure z_stream
*next_in.BYTE
avail_in.l
total_in.l ; uLong
*next_out.BYTE
avail_out.l
total_out.l ; uLong
*msg.BYTE
*state
zalloc.i
zfree.i
opaque.i
data_type.l
adler.l ; uLong
reserved.l ; uLong
; without this, the inflateInit2() fails with a version error
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
alignment.l
CompilerEndIf
EndStructure
CompilerEndIf
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
#ZLib_Library = "zlib.lib"
CompilerElse
#ZLib_Library = "-lz"
CompilerEndIf
ImportC #ZLib_Library
; Note: These do not work with zip data, as they expect a zlib header
; But they are used for non-zip compression (example: EditHistory)
;
; Note also here the Windows/Linux difference on 64bit.
; It should be ok to use the methods with all INTEGER types as long as they
; have no garbage in their upper 32bits
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64 And #PB_Compiler_OS <> #PB_OS_Windows
compress.l(*dest, *destlen.INTEGER, *source, sourcelen.i)
compress2.l(*dest, *destlen.INTEGER, *source, sourcelen.i, level.l)
uncompress.l(*dest, *destlen.INTEGER, *source, sourcelen.i)
compressBound.i(sourcelen.i)
CompilerElse
compress.l(*dest, *destlen.LONG, *source, sourcelen.l)
compress2.l(*dest, *destlen.LONG, *source, sourcelen.l, level.l)
uncompress.l(*dest, *destlen.LONG, *source, sourcelen.l)
compressBound.l(sourcelen.l)
CompilerEndIf
; ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
; According to zlib.h, calling inflateInit2
; with a negative window size enters "raw mode",
; which we need for zip extraction
;
; It also notes that it needs an extra input byte in this mode to finish
; properly. (to be checked)
;
inflateInit2_.l(*stream.z_stream, windowBits.l, *version, streamsize.l)
inflate.l(*stream.z_stream, flush.l)
inflateEnd.l(*stream.z_stream)
EndImport
; definition of the zlib macro
Macro inflateInit2(stream, windowBits)
inflateInit2_(stream, windowBits, @"1.2.5", SizeOf(z_stream))
EndMacro