mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 08:47:28 +01:00
Let the zlib decoder ignore the checksum
This commit is contained in:
1 parent
fdceee4bd0
commit
446d4662db
4 files changed
+69
-26
No files matched your search
@@ -26,8 +26,13 @@ pub error "TODO: unsupported zlib preset dictionary"
|
||||
pub struct decoder?(
|
||||
flate deflate.decoder,
|
||||
adler adler32,
|
||||
ignore_checksum bool,
|
||||
)
|
||||
|
||||
pub func decoder.set_ignore_checksum!(ic bool)() {
|
||||
this.ignore_checksum = in.ic
|
||||
}
|
||||
|
||||
pub func decoder.decode?(dst writer1, src reader1)() {
|
||||
var x u16 = in.src.read_u16be?()
|
||||
if ((x >> 8) & 0x0F) != 0x08 {
|
||||
@@ -46,15 +51,15 @@ pub func decoder.decode?(dst writer1, src reader1)() {
|
||||
while true {
|
||||
in.dst.mark()
|
||||
var z status = try this.flate.decode?(dst:in.dst, src:in.src)
|
||||
// TODO: expose some API to opt out of checksumming, trading off error
|
||||
// detection for throughput.
|
||||
checksum = this.adler.update(x:in.dst.since_mark())
|
||||
if not this.ignore_checksum {
|
||||
checksum = this.adler.update(x:in.dst.since_mark())
|
||||
}
|
||||
if z.is_ok() {
|
||||
break
|
||||
}
|
||||
yield z
|
||||
}
|
||||
if checksum != in.src.read_u32be?() {
|
||||
if (not this.ignore_checksum) and (checksum != in.src.read_u32be?()) {
|
||||
return error "checksum mismatch"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user