diff --git a/script/extract-flate-offsets.go b/script/extract-flate-offsets.go index da070b2c..bb7794ea 100644 --- a/script/extract-flate-offsets.go +++ b/script/extract-flate-offsets.go @@ -10,6 +10,8 @@ package main // // Usage: go run extract-flate-offsets.go foo.gz bar.gz // +// Alternatively: go run extract-flate-offsets.go -write-flate foo.gz +// // Alternatively: go run extract-flate-offsets.go -write-zlib foo.gz import ( @@ -26,7 +28,8 @@ import ( ) var ( - writeZlib = flag.Bool("write-zlib", false, "whether to convert gzip to zlib") + 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") ) // GZIP wraps a header and footer around flate data. The format is described in @@ -102,13 +105,27 @@ func decode(filename string) error { return err } - if *writeZlib { + if *writeFlate { + return doWriteFlate(src[i:], uncompressed, filename) + } else if *writeZlib { return doWriteZlib(src[i:], uncompressed, filename) } fmt.Printf("%7d %7d %x %s\n", i, len(src), md5.Sum(uncompressed), filename) return nil } +func doWriteFlate(flateCompressed []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 { + return err + } + fmt.Printf("wrote %s\n", filename) + return nil +} + func doWriteZlib(flateCompressed []byte, uncompressed []byte, filename string) error { buf := bytes.NewBuffer(nil) // The ZLIB header (as per https://www.ietf.org/rfc/rfc1950.txt) is 2 diff --git a/test/testdata/README.md b/test/testdata/README.md index 52a2c30e..c44dd720 100644 --- a/test/testdata/README.md +++ b/test/testdata/README.md @@ -1,9 +1,20 @@ +Unless otherwise noted, the *.gz files were generated by the gzip command line +tool and the .flate and .zlib versions were then generated by +script/extract-flate-offsets.go. Similarly, the *.giflzw files were generated +by script/extract-giflzw.go and the *.palette and *.indexes files were +generated by script/extract-palette-indexes.go + +The *.jpeg files are usually the canonical versions of the testdata images, and +other versions (*.bmp, *.gif, *.png, *.tiff) were generated by ImageMagick's +convert command line tool. The *.webp versions were generated by the cwebp +command line tool. + + + 256.bytes just holds "\x00\x01\x02\x03...\xff". bricks-* are various encodings of an original photo by Nigel Tao -. The *.giflzw files were generated by -script/extract-giflzw.go and the *.palette and *.indexes files were generated -by script/extract-palette-indexes.go +. harvesters.* are various encodings of a photo of "The Harvesters" by Pieter Bruegel the Elder, held by the Metropolitan Museum of Art. @@ -30,8 +41,7 @@ Museum." midsummer.txt is an excerpt of Shakespeare's "A Midsummer Night's Dream", copied from http://shakespeare.mit.edu/midsummer/midsummer.1.1.html -pi.txt contains the digits of pi. The *.giflzw file was generated by -script/compress-giflzw.go +pi.txt contains the digits of pi. pjw-thumbnail.* are various encodings of an image derived from an iconic, original photo of Peter J. Weinberger by Rob Pike . diff --git a/test/testdata/romeo.txt.flate b/test/testdata/romeo.txt.flate new file mode 100644 index 00000000..61baf35f Binary files /dev/null and b/test/testdata/romeo.txt.flate differ diff --git a/test/testdata/romeo.txt.zlib b/test/testdata/romeo.txt.zlib new file mode 100644 index 00000000..13ee84d3 Binary files /dev/null and b/test/testdata/romeo.txt.zlib differ