https://github.com/ralscha/zopfli-go
https://github.com/ralscha/zopfli-go
Last synced: 17 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ralscha/zopfli-go
- Owner: ralscha
- Created: 2026-03-31T03:47:28.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-05-31T13:52:37.000Z (26 days ago)
- Last Synced: 2026-05-31T15:21:56.267Z (26 days ago)
- Language: Go
- Size: 85 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# zopfli-go
`zopfli-go` is a pure Go implementation of Zopfli-style compression for `gzip`, `zlib`, and raw `deflate` output.
## Go Usage
```go
package main
import zopfli "github.com/ralscha/zopfli-go"
func main() {
compressed := zopfli.Gzip([]byte("hello, world"))
}
```
For custom tuning, use `DefaultOptions()` and call `Compress` with `FormatGzip`, `FormatZlib`, or `FormatDeflate`.
```go
package main
import zopfli "github.com/ralscha/zopfli-go"
func main() {
options := zopfli.DefaultOptions()
options.NumIterations = 5
options.BlockSplittingMax = 8
compressed := zopfli.Compress(&options, zopfli.FormatGzip, []byte("hello, tuned world"))
}
```
## CLI Usage
The repository includes a file-oriented CLI for precompressing web assets into adjacent `.gz` files.
```bash
./zopfli-go --help
./zopfli-go --jobs 8 public
./zopfli-go --include-suffix .js --exclude-suffix .min.js public
./zopfli-go public assets/app.js
./zopfli-go --json public
```
Behavior:
- File and directory inputs are accepted.
- Directories are walked recursively.
- Outputs are written next to the source file as `filename.ext.gz`.
- Files are skipped when the `.gz` output is larger than or equal to the original.
- Existing `.gz` files are ignored as inputs unless `--allow-gzip-inputs` is set.
Supported CLI flags:
- `-j`, `--jobs`
- `-i`, `--include-suffix` and `-x`, `--exclude-suffix` (repeatable, matched against relative paths or base filenames)
- `--allow-gzip-inputs`
- `-n`, `--iterations`
- `--block-splitting`
- `--block-splitting-last=false|true|both`
- `--block-splitting-max`
- `-v`, `--verbose`
- `-V`, `--verbose-more`
- `-J`, `--json`
## Benchmarks
The table below is updated by the benchmark workflow on branch pushes and workflow dispatches.
Benchmark comparisons use the original upstream Zopfli implementation from https://github.com/google/zopfli.
| Corpus | GoMs | PgoMs | CMs | PGO/Go | Go/C | PGO/C | GoBytes | CBytes | GzipBytes |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
| mixed-256k | 2956.48 | 2830.11 | 7642.54 | 0.96 | 0.39 | 0.37 | 3162 | 3162 | 3204 |
| random-256k | 434.12 | 423.88 | 403.26 | 0.98 | 1.08 | 1.05 | 262183 | 262183 | 262247 |
| real-files-256k | 1073.41 | 1023.49 | 2579.72 | 0.95 | 0.42 | 0.40 | 4649 | 4649 | 5042 |
| records-logs-256k | 1194.19 | 1119.80 | 2238.98 | 0.94 | 0.53 | 0.50 | 2510 | 2510 | 2662 |
| tiny-text | 32.31 | 31.22 | 30.55 | 0.97 | 1.06 | 1.02 | 58 | 58 | 65 |
| web-assets-256k | 1065.11 | 999.36 | 2318.37 | 0.94 | 0.46 | 0.43 | 3756 | 3756 | 4078 |
## Development
Run the package tests with:
```bash
go test ./...
```
Generate the benchmark summary locally with:
```bash
go run ./cmd/zopfli-task bench-summary
```
## Releases
GitHub releases are produced by GoReleaser from version tags such as `v1.0.0`.
Release assets are archived as `.tar.gz` on Linux and macOS, and as `.zip` on Windows.
Those release assets are consumed directly by `bread-compressor-cli` when its `--use-zopfli-go` flag is enabled.