(Copying Ivan Krasin because I believe this is his code originally.)
This has turned out to be a bit harder than I hoped. I've been running into trouble with deflate when the window size is smaller than the maximum match length (258).
If flate.logWindowSize == 8 (which is the minimum allowed by spec), then the window will be 256 bytes and flate.deflate() will crash when the window is adjusted because the index will be negative:
panic: runtime error: index out of range
goroutine 1 [running]:
ztest/compress/flate.(*compressor).deflate(0x2081c8900)
/Users/rnapier/go/src/ztest/compress/flate/deflate.go:235 +0xff9
I've posted example code to demonstrate:
https://github.com/rnapier/ztest
I'm still digging into how to address this, consulting the equivalent zlib code. Simply reducing maxMatchLength to 128 seems to fix it, but zlib doesn't require this hack, so I'm thinking that's the wrong direction.
Insights welcome.
Thanks,
-Rob