mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 08:38:14 +01:00
Delete std/flate's zlib code (moved to std/zlib)
This commit is contained in:
1 parent
7e73a5ac5f
commit
530605a16b
8 files changed
+42
-736
No files matched your search
+7
-3
@@ -15,8 +15,11 @@ file formats.
|
||||
is another wrapper, similar to combining gzip with tar, that can compress
|
||||
multiple files into a single archive. Zip is widely used by the ECMA Office
|
||||
Open XML format, the OASIS Open Document Format for Office Applications and the
|
||||
Java JAR format. Parsing zip is not provided by this package, look at the
|
||||
`std/zip` package instead (TODO).
|
||||
Java JAR format.
|
||||
|
||||
Wrangling those formats that build on flate (gzip, zip and zlib) is not
|
||||
provided by this package. For zlib, look at the `std/zlib` package instead. The
|
||||
other formats are TODO.
|
||||
|
||||
For example, look at `test/testdata/romeo.txt*`. First, the uncompressed text:
|
||||
|
||||
@@ -50,7 +53,8 @@ uncompressed file (0x3ae = 942 bytes).
|
||||
00000220: 7a59 610d 7f01 ef07 e5ab ae03 0000 zYa...........
|
||||
|
||||
The zlib format wraps a 2 byte header and 4 byte footer around the raw flate
|
||||
data. The footer contains a 4 byte Adler32 checksum.
|
||||
data. The footer contains a 4 byte Adler32 checksum. TODO: move this to
|
||||
std/zlib/README.md.
|
||||
|
||||
$ xxd test/testdata/romeo.txt.zlib
|
||||
00000000: 789c 4d53 c16e db30 0cbd f32b d853 2e46 x.MS.n.0...+.S.F
|
||||
|
||||
@@ -16,10 +16,6 @@ packageid "flte"
|
||||
|
||||
// TODO: rename "struct flate_decoder" to just "struct decoder", to avoid
|
||||
// stutter in the fully qualified C name such as "wuffs_flate__flate_decoder".
|
||||
//
|
||||
// TODO: delete std/flate/decode_zlib.wuffs, and update std/flate/README.md.
|
||||
//
|
||||
// Would we then need to somehow share code between test/c/std/{flate,gzip}.c?
|
||||
|
||||
// TODO: rename flate to deflate, since that's what RFC 1951 calls it.
|
||||
|
||||
@@ -33,7 +29,6 @@ pub error "bad distance"
|
||||
pub error "bad distance code count"
|
||||
pub error "bad flate block"
|
||||
pub error "bad literal/length code count"
|
||||
pub error "checksum mismatch" // TODO: delete this.
|
||||
pub error "inconsistent stored block length"
|
||||
pub error "internal error: inconsistent Huffman decoder state"
|
||||
pub error "internal error: inconsistent Huffman end_of_block"
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
// Copyright 2017 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// TODO: delete this file. Its contents have been copy/pasted to std/zlib.
|
||||
|
||||
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?(
|
||||
flate flate_decoder,
|
||||
adler adler32,
|
||||
)
|
||||
|
||||
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"
|
||||
}
|
||||
var checksum u32
|
||||
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 z.is_ok() {
|
||||
break
|
||||
}
|
||||
yield z
|
||||
}
|
||||
if checksum != in.src.read_u32be?() {
|
||||
return error "checksum mismatch"
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: drop the '?' but still generate wuffs_flate_adler_initialize?
|
||||
pri struct adler32?(
|
||||
state u32 = 1,
|
||||
)
|
||||
|
||||
// TODO: add a ! as this function is impure.
|
||||
pri func adler32.update(x[] u8)(checksum u32) {
|
||||
// The Adler-32 checksum's magic 65521 and 5552 numbers are discussed in
|
||||
// RFC 1950.
|
||||
|
||||
var s1 u32 = this.state.low_bits(n:16)
|
||||
var s2 u32 = this.state.high_bits(n:16)
|
||||
|
||||
while in.x.length() > 0 {
|
||||
var remaining[] u8
|
||||
if in.x.length() > 5552 {
|
||||
remaining = in.x[5552:]
|
||||
in.x = in.x[:5552]
|
||||
}
|
||||
|
||||
iterate.8 (p ptr u8:in.x) {
|
||||
s1 ~+= deref p as u32
|
||||
s2 ~+= s1
|
||||
}
|
||||
|
||||
s1 %= 65521
|
||||
s2 %= 65521
|
||||
|
||||
in.x = remaining
|
||||
}
|
||||
|
||||
this.state = ((s2 & 0xFFFF) << 16) | (s1 & 0xFFFF)
|
||||
return this.state
|
||||
}
|
||||
Reference in new issue
Block a user