mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 00:47:28 +01:00
Add a zlib decoder to std/flate.
This commit is contained in:
1 parent
2e6b364dcc
commit
b3710e583f
13 files changed
+566
-117
No files matched your search
@@ -0,0 +1,31 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be found
|
||||
// in the LICENSE file.
|
||||
|
||||
pub error "invalid zlib compression method"
|
||||
pub error "invalid zlib compression window size"
|
||||
pub error "invalid zlib parity check"
|
||||
|
||||
pub error "TODO: unsupported zlib preset dictionary"
|
||||
|
||||
pub struct zlib_decoder?(
|
||||
dec decoder,
|
||||
)
|
||||
|
||||
pub func zlib_decoder.decode?(dst writer1, src reader1)() {
|
||||
var x u16 = in.src.read_u16be?()
|
||||
if ((x >> 8) & 0x0F) != 0x08 {
|
||||
return error "invalid zlib compression method"
|
||||
}
|
||||
if (x >> 12) > 0x07 {
|
||||
return error "invalid zlib compression window size"
|
||||
}
|
||||
if (x & 0x20) != 0 {
|
||||
return error "TODO: unsupported zlib preset dictionary"
|
||||
}
|
||||
if (x % 31) != 0 {
|
||||
return error "invalid zlib parity check"
|
||||
}
|
||||
this.dec.decode?(dst:in.dst, src:in.src)
|
||||
var checksum u32 = in.src.read_u32be?()
|
||||
// TODO: verify the checksum.
|
||||
}
|
||||
Reference in new issue
Block a user