zsync is a file transfer program (Go implementation) that downloads only changed blocks of a file using rolling checksums and a control file (.zsync). Two binaries: zsync (client) and zsyncmake (server-side control file generator).
- Language: Go 1.25.0
- Module:
github.com/cph6/zsync - License: Artistic 2.0
- Maintainer: Colin Phipps [email protected]
go build -o zsync ./cmd/zsync
go build -o zsyncmake ./cmd/zsyncmakeBinary entrypoints: cmd/zsync/main.go, cmd/zsyncmake/main.go
syncer.go/syncer_test.go: Core Syncer library—loads.zsynccontrol files, reconstructs target files from local seed + remote blocks. Primary public API. Not thread-safe exceptStatus()andProgress().control_file_parse.go: Parse.zsynccontrol file format (text headers + binary checksums).control_file_fetch.go: Fetch target file blocks via HTTP(S).target_fetch.go: Download file blocks, handle ranges, retries.internal/rcksum/: Rolling checksum + MD4 hashing (core sync algorithm).internal/httpbasic/: HTTP Basic Auth support.cmd/zsync/main.go: CLI for end-users. Wraps Syncer library.cmd/zsyncmake/main.go: CLI to generate.zsynccontrol files from target files.
Key library types:
Syncer: State machine for reconstruction; manage withNew(),FetchRemainingBlocks(),Complete(),End().SeedReader: Feed local file data to match against existing blocks.HTTPRequester: HTTP client interface (allows test injection).
Short tests (unit):
go test -short ./...Full integration tests (requires Apache, OpenSSL, tinyproxy):
LARGE_TESTS=yes go test ./...Single test:
go test -v -run TestZSyncMakeSimple ./t/zsyncTest structure:
- Unit tests in
*_test.goalongside source (e.g.,syncer_test.go,internal/rcksum/*_test.go). - Integration tests in
t/zsync/andt/zsyncmake/with Apache HTTP server, TLS certs, proxy support. - Test data in
t/data/(generated); logs int/logs/. t/server_setup.go: Spawns Apache, sets up HTTPS, proxy.- Note: integration tests are slow; run
-shortfor quick feedback.
- Many functions include
// AI: <model>comments marking AI-assisted code sections (e.g., GPT, Copilot, Claude). - Preserved from original C codebase; use these as context hints when refactoring or extending logic.
- SPDX headers on all files; maintain them.
golangci-lint runConfig: .golangci.yaml (staticcheck with some exceptions: -SA1019 for deprecated code, -QF1001 for questionable format).
- API Stability: v0.x version number—public API may change. NEWS file tracks breaking changes (v0.7.0 was major rewrite from HTTP pipelining to HTTP/2).
- Library Mode: As of v0.7.2, zsync is usable as a Go module (Syncer exported as public API). CLI is thin wrapper around library.
- Control File Format: Binary checksums follow text headers; see
control_file_parse.gofor format details (rsum, blocksize, hash lengths, etc.). - HTTP Ranges: Uses HTTP 206 Partial Content;
target_fetch.gohandles range requests and retries. - Testing Preconditions: Full tests need Apache, OpenSSL, tinyproxy installed (even if not running—tests spawn them). Proxy tests need local IP (not localhost) due to Go HTTP client proxy rules.
- Man Pages: In
man/(zsync.1, zsyncmake.1); update if CLI changes.
| Task | Command |
|---|---|
| Build both binaries | go build -o zsync ./cmd/zsync && go build -o zsyncmake ./cmd/zsyncmake |
| Run unit tests | go test -short ./... |
| Run specific test | go test -v -run TestName ./path/to/package |
| Full test suite (slow) | LARGE_TESTS=yes go test ./... |
| Lint | golangci-lint run |
| Check module deps | go mod tidy && git diff go.* |
- v0.7.2 (current): Fixed stdin crash in zsyncmake, continual progress reporting, library-mode support.
- v0.7.0: Complete rewrite—dropped HTTP pipelining, added HTTP/2 + HTTPS, removed gzip introspection.
- Extensive refactoring since—see git log for details.
- Gzip files: only supported if compressed with
--rsyncable; legacy gzip introspection removed. - Proxy tests may be flaky on systems without clear local IP; see
t/zsync/server_setup.go.