annotate semicongine/thirdparty/zippy/zippy.nim @ 1123:657bb0b2af45

add: thirdparty libraries into repo
author sam <sam@basx.dev>
date Sat, 27 Apr 2024 22:04:30 +0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1123
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
1 import zippy/adler32, zippy/common, zippy/crc, zippy/deflate,
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
2 zippy/gzip, zippy/inflate, zippy/internal
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
3
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
4 when (NimMajor, NimMinor, NimPatch) >= (1, 6, 0):
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
5 import std/sysrand
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
6 else:
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
7 import std/random, std/times
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
8
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
9 export common
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
10
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
11 proc compress*(
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
12 src: pointer,
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
13 len: int,
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
14 level = DefaultCompression,
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
15 dataFormat = dfGzip
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
16 ): string {.raises: [ZippyError].} =
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
17 ## Compresses src and returns the compressed data.
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
18 let src = cast[ptr UncheckedArray[uint8]](src)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
19
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
20 case dataFormat:
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
21 of dfGzip:
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
22 result.setLen(10)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
23 result[0] = 31.char
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
24 result[1] = 139.char
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
25 result[2] = 8.char
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
26 result[3] = (1.uint8 shl 3).char # Set the fname flag
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
27
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
28 block: # https://github.com/guzba/zippy/issues/61
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
29 let htbLen =
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
30 when (NimMajor, NimMinor, NimPatch) >= (1, 6, 0):
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
31 var urand: array[1, uint8]
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
32 if not urandom(urand):
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
33 raise newException(ZippyError, "Failed to generate random number")
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
34 (urand[0] mod 26).int
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
35 else:
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
36 let now = getTime()
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
37 var rand = initRand(now.toUnix * 1_000_000_000 + now.nanosecond)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
38 (rand.next() mod 26).int # mod the uint first to ensure a positive int
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
39 # Add up to 26 characters as the gzip header file name
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
40 for i in 0 ..< htbLen:
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
41 result.add (97 + i).char
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
42 result.add '\0'
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
43
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
44 deflate(result, src, len, level)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
45
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
46 let
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
47 checksum = crc32(src, len)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
48 isize = len
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
49
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
50 result.add(((checksum shr 0) and 255).char)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
51 result.add(((checksum shr 8) and 255).char)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
52 result.add(((checksum shr 16) and 255).char)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
53 result.add(((checksum shr 24) and 255).char)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
54
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
55 result.add(((isize shr 0) and 255).char)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
56 result.add(((isize shr 8) and 255).char)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
57 result.add(((isize shr 16) and 255).char)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
58 result.add(((isize shr 24) and 255).char)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
59
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
60 of dfZlib:
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
61 const
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
62 cm = 8.uint8
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
63 cinfo = 7.uint8
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
64 cmf = (cinfo shl 4) or cm
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
65 fcheck = (31.uint32 - (cmf.uint32 * 256) mod 31).uint8
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
66
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
67 result.setLen(2)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
68 result[0] = cmf.char
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
69 result[1] = fcheck.char
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
70
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
71 deflate(result, src, len, level)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
72
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
73 let checksum = adler32(src, len)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
74
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
75 result.add(((checksum shr 24) and 255).char)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
76 result.add(((checksum shr 16) and 255).char)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
77 result.add(((checksum shr 8) and 255).char)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
78 result.add(((checksum shr 0) and 255).char)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
79
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
80 of dfDeflate:
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
81 deflate(result, src, len, level)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
82
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
83 else:
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
84 raise newException(ZippyError, "Invalid data format " & $dfDetect)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
85
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
86 proc compress*(
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
87 src: string,
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
88 level = DefaultCompression,
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
89 dataFormat = dfGzip
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
90 ): string {.raises: [ZippyError].} =
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
91 compress(src.cstring, src.len, level, dataFormat)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
92
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
93 proc compress*(
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
94 src: seq[uint8],
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
95 level = DefaultCompression,
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
96 dataFormat = dfGzip
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
97 ): seq[uint8] {.raises: [ZippyError].} =
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
98 cast[seq[uint8]](compress(cast[string](src).cstring, src.len, level, dataFormat))
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
99
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
100 proc uncompress*(
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
101 src: pointer,
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
102 len: int,
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
103 dataFormat = dfDetect
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
104 ): string {.raises: [ZippyError].} =
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
105 ## Uncompresses src and returns the uncompressed data.
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
106 let src = cast[ptr UncheckedArray[uint8]](src)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
107
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
108 case dataFormat:
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
109 of dfDetect:
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
110 if (
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
111 len > 18 and
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
112 src[0].uint8 == 31 and src[1].uint8 == 139 and src[2].uint8 == 8 and
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
113 (src[3].uint8 and 0b11100000) == 0
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
114 ):
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
115 return uncompress(src, len, dfGzip)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
116
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
117 if (
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
118 len > 6 and
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
119 (src[0].uint8 and 0b00001111) == 8 and
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
120 (src[0].uint8 shr 4) <= 7 and
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
121 ((src[0].uint16 * 256) + src[1].uint8) mod 31 == 0
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
122 ):
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
123 return uncompress(src, len, dfZlib)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
124
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
125 raise newException(ZippyError, "Unable to detect compressed data format")
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
126
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
127 of dfGzip:
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
128 uncompressGzip(result, src, len)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
129
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
130 of dfZlib:
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
131 if len < 6:
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
132 failUncompress()
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
133
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
134 let
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
135 cmf = src[0].uint8
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
136 flg = src[1].uint8
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
137 cm = cmf and 0b00001111
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
138 cinfo = cmf shr 4
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
139
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
140 if cm != 8: # DEFLATE
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
141 raise newException(ZippyError, "Unsupported compression method")
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
142
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
143 if cinfo > 7.uint8:
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
144 raise newException(ZippyError, "Invalid compression info")
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
145
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
146 if ((cmf.uint16 * 256) + flg.uint16) mod 31 != 0:
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
147 raise newException(ZippyError, "Invalid header")
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
148
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
149 if (flg and 0b00100000) != 0: # FDICT
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
150 raise newException(ZippyError, "Preset dictionary is not yet supported")
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
151
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
152 inflate(result, src, len, 2)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
153
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
154 let checksum = (
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
155 src[len - 4].uint32 shl 24 or
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
156 src[len - 3].uint32 shl 16 or
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
157 src[len - 2].uint32 shl 8 or
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
158 src[len - 1].uint32
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
159 )
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
160
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
161 if checksum != adler32(result):
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
162 raise newException(ZippyError, "Checksum verification failed")
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
163
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
164 of dfDeflate:
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
165 inflate(result, src, len, 0)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
166
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
167 proc uncompress*(
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
168 src: string,
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
169 dataFormat = dfDetect
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
170 ): string {.raises: [ZippyError].} =
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
171 uncompress(src.cstring, src.len, dataFormat)
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
172
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
173 proc uncompress*(
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
174 src: seq[uint8],
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
175 dataFormat = dfDetect
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
176 ): seq[uint8] {.raises: [ZippyError].} =
657bb0b2af45 add: thirdparty libraries into repo
sam <sam@basx.dev>
parents:
diff changeset
177 cast[seq[uint8]](uncompress(cast[string](src).cstring, src.len, dataFormat))