diff --git a/script/extract-flate-offsets.go b/script/extract-deflate-offsets.go similarity index 77% rename from script/extract-flate-offsets.go rename to script/extract-deflate-offsets.go index 437d2b72..645b6486 100644 --- a/script/extract-flate-offsets.go +++ b/script/extract-deflate-offsets.go @@ -16,14 +16,14 @@ package main -// extract-flate-offsets.go extracts the start and end offsets of the -// flate-compressed data wrapped in a .gz file. +// extract-deflate-offsets.go extracts the start and end offsets of the +// deflate-compressed data wrapped in a .gz file. // -// Usage: go run extract-flate-offsets.go foo.gz bar.gz +// Usage: go run extract-deflate-offsets.go foo.gz bar.gz // -// Alternatively: go run extract-flate-offsets.go -write-flate foo.gz +// Alternatively: go run extract-deflate-offsets.go -write-deflate foo.gz // -// Alternatively: go run extract-flate-offsets.go -write-zlib foo.gz +// Alternatively: go run extract-deflate-offsets.go -write-zlib foo.gz import ( "bytes" @@ -39,11 +39,11 @@ import ( ) var ( - writeFlate = flag.Bool("write-flate", false, "whether to convert gzip to raw flate") - writeZlib = flag.Bool("write-zlib", false, "whether to convert gzip to zlib") + writeDeflate = flag.Bool("write-deflate", false, "whether to convert gzip to raw deflate") + writeZlib = flag.Bool("write-zlib", false, "whether to convert gzip to zlib") ) -// GZIP wraps a header and footer around flate data. The format is described in +// GZIP wraps a header and footer around deflate data. The format is described in // RFC 1952: https://www.ietf.org/rfc/rfc1952.txt const ( flagText = 1 << 0 @@ -110,14 +110,14 @@ func decode(filename string) error { return fmt.Errorf("TODO: support gzip HCRC flag") } - // As a sanity check, the result should be valid flate. - uncompressed, err := checkFlate(src[i:]) + // As a sanity check, the result should be valid deflate. + uncompressed, err := checkDeflate(src[i:]) if err != nil { return err } - if *writeFlate { - return doWriteFlate(src[i:], uncompressed, filename) + if *writeDeflate { + return doWriteDeflate(src[i:], uncompressed, filename) } else if *writeZlib { return doWriteZlib(src[i:], uncompressed, filename) } @@ -125,33 +125,33 @@ func decode(filename string) error { return nil } -func doWriteFlate(flateCompressed []byte, uncompressed []byte, filename string) error { +func doWriteDeflate(deflateCompressed []byte, uncompressed []byte, filename string) error { if strings.HasSuffix(filename, ".gz") { filename = filename[:len(filename)-3] } - filename += ".flate" - if err := ioutil.WriteFile(filename, flateCompressed, 0666); err != nil { + filename += ".deflate" + if err := ioutil.WriteFile(filename, deflateCompressed, 0666); err != nil { return err } fmt.Printf("wrote %s\n", filename) return nil } -func doWriteZlib(flateCompressed []byte, uncompressed []byte, filename string) error { +func doWriteZlib(deflateCompressed []byte, uncompressed []byte, filename string) error { buf := bytes.NewBuffer(nil) // The ZLIB header (as per https://www.ietf.org/rfc/rfc1950.txt) is 2 // bytes. // - // The first byte's low 4 bits is the compression method: 8 means flate. + // The first byte's low 4 bits is the compression method: 8 means deflate. // The first byte's high 4 bits is the compression info: 7 means a 32KiB - // flate window size. + // deflate window size. // // The second byte's low 5 bits are a parity check. The 5th bit (0 in this // case) indicates a preset dictionary. The high 2 bits (2 in this case) // means the default compression algorithm. buf.WriteString("\x78\x9c") // Write the payload. - buf.Write(flateCompressed) + buf.Write(deflateCompressed) // The ZLIB footer is 4 bytes: a big-endian checksum. checksum := adler32.Checksum(uncompressed) buf.WriteByte(uint8(checksum >> 24)) @@ -189,12 +189,12 @@ func readString(src []byte, i int) (int, error) { } } -func checkFlate(x []byte) ([]byte, error) { +func checkDeflate(x []byte) ([]byte, error) { rc := flate.NewReader(bytes.NewReader(x)) defer rc.Close() x, err := ioutil.ReadAll(rc) if err != nil { - return nil, fmt.Errorf("data is not valid flate: %v", err) + return nil, fmt.Errorf("data is not valid deflate: %v", err) } return x, nil } diff --git a/script/print-flate-magic-numbers.go b/script/print-deflate-magic-numbers.go similarity index 90% rename from script/print-flate-magic-numbers.go rename to script/print-deflate-magic-numbers.go index 1b5a55a0..01289d6f 100644 --- a/script/print-flate-magic-numbers.go +++ b/script/print-deflate-magic-numbers.go @@ -16,10 +16,10 @@ package main -// print-flate-magic-numbers.go prints the std/flate lcode_magic_numbers values -// based on the tables in RFC 1951 secion 3.2.5. +// print-deflate-magic-numbers.go prints the std/deflate lcode_magic_numbers +// values based on the tables in RFC 1951 secion 3.2.5. // -// Usage: go run print-flate-magic-numbers.go +// Usage: go run print-deflate-magic-numbers.go import ( "fmt" diff --git a/script/wuffs-flate-decoder-decode-huffman.c b/script/wuffs-deflate-decoder-decode-huffman.c similarity index 87% rename from script/wuffs-flate-decoder-decode-huffman.c rename to script/wuffs-deflate-decoder-decode-huffman.c index 512289a2..2202de64 100644 --- a/script/wuffs-flate-decoder-decode-huffman.c +++ b/script/wuffs-deflate-decoder-decode-huffman.c @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -// This file contains a hand-written C implementation of gen/c/std/flate.c's -// generated wuffs_flate__flate_decoder__decode_huffman_fast function. +// This file contains a hand-written C implementation of gen/c/std/deflate.c's +// generated wuffs_deflate__decoder__decode_huffman_fast function. // // It is not intended to be used in production settings, on untrusted data. Its // purpose is to give a rough upper bound on how fast Wuffs' generated C code @@ -21,29 +21,31 @@ // // To repeat, substituting in this C implementation is NOT SAFE, and may result // in buffer overflows. This code exists only to aid optimization of the (safe) -// std/flate/*.wuffs code and the Wuffs compiler's code generation. +// std/deflate/*.wuffs code and the Wuffs compiler's code generation. // // ---------------- // // Having said that, to generate the benchmark numbers with this hand-written C -// implementation, edit gen/c/std/flate.c and find the line that says +// implementation, edit gen/c/std/deflate.c and find the line that says // // C HEADER ENDS HERE. // // After that, add this line: // -// #include "../../../script/wuffs-flate-decoder-decode-huffman.c" +// #include "../../../script/wuffs-deflate-decoder-decode-huffman.c" // -// Then find the call to wuffs_flate__flate_decoder__decode_huffman_fast. It -// should be inside the wuffs_flate__flate_decoder__decode_blocks function body, -// and the lines of code should look something like +// Then find the call to wuffs_deflate__decoder__decode_huffman_fast. It should +// be inside the wuffs_deflate__decoder__decode_blocks function body, and the +// lines of code should look something like // // status = -// wuffs_flate__flate_decoder__decode_huffman_fast(self, a_dst, a_src); +// wuffs_deflate__decoder__decode_huffman_fast(self, a_dst, a_src); // // Change the "wuffs" to "c_wuffs", i.e. add a "c_" prefix. The net result // should look something like: // +// TODO: update this "git diff" snippet. +// // ---------------- // // $ git diff gen/c/std/flate.c @@ -74,17 +76,17 @@ // // ---------------- // -// That concludes the two edits to gen/c/std/flate.c. Run the tests and +// That concludes the two edits to gen/c/std/deflate.c. Run the tests and // benchmarks with the "-skipgen" flag, otherwise the "wuffs" tool will -// re-generate the C code and override your gen/c/std/flate.c edit: +// re-generate the C code and override your gen/c/std/deflate.c edit: // -// wuffs test -skipgen std/flate -// wuffs bench -skipgen std/flate +// wuffs test -skipgen std/deflate +// wuffs bench -skipgen std/deflate // // You may also want to focus on one specific test, e.g.: // -// wuffs test -skipgen -focus=wuffs_flate_decode_midsummer std/flate -// wuffs bench -skipgen -focus=wuffs_flate_decode_100k std/flate +// wuffs test -skipgen -focus=wuffs_deflate_decode_midsummer std/deflate +// wuffs bench -skipgen -focus=wuffs_deflate_decode_100k std/deflate #include #include // For manual printf debugging. @@ -103,24 +105,24 @@ // This is the generated function that we are explicitly overriding. Note that // the function name is "wuffs_etc", not "c_wuffs_etc". -static wuffs_flate__status wuffs_flate__flate_decoder__decode_huffman_fast( - wuffs_flate__flate_decoder* self, +static wuffs_deflate__status wuffs_deflate__decoder__decode_huffman_fast( + wuffs_deflate__decoder* self, wuffs_base__writer1 a_dst, wuffs_base__reader1 a_src); // This is the overriding implementation. -wuffs_flate__status c_wuffs_flate__flate_decoder__decode_huffman_fast( - wuffs_flate__flate_decoder* self, +wuffs_deflate__status c_wuffs_deflate__decoder__decode_huffman_fast( + wuffs_deflate__decoder* self, wuffs_base__writer1 a_dst, wuffs_base__reader1 a_src) { // Avoid the -Werror=unused-function warning for the now-unused - // overridden wuffs_flate__flate_decoder__decode_huffman_fast. - (void)(wuffs_flate__flate_decoder__decode_huffman_fast); + // overridden wuffs_deflate__decoder__decode_huffman_fast. + (void)(wuffs_deflate__decoder__decode_huffman_fast); if (!a_dst.buf || !a_src.buf) { return WUFFS_FLATE__ERROR_BAD_ARGUMENT; } - wuffs_flate__status status = WUFFS_FLATE__STATUS_OK; + wuffs_deflate__status status = WUFFS_FLATE__STATUS_OK; // Load contextual state. Prepare to check that pdst and psrc remain within // a_dst's and a_src's bounds. diff --git a/std/deflate/decode_deflate.wuffs b/std/deflate/decode_deflate.wuffs index 7382750e..ddc3316b 100644 --- a/std/deflate/decode_deflate.wuffs +++ b/std/deflate/decode_deflate.wuffs @@ -32,7 +32,7 @@ pub error "internal error: inconsistent n_bits" pub error "missing end-of-block code" pub error "no Huffman codes" -// The next two tables were created by script/print-flate-magic-numbers.go. +// The next two tables were created by script/print-deflate-magic-numbers.go. // // The u32 values' meanings are the same as the decoder.huffs u32 values. In // particular, bit 30 indicates a base number + extra bits, bits 23-8 are the