Sample
github.com/klauspost/compress v1.19.1
Verified sample for golang github.com/klauspost/compress v1.19.1. The contract ran on go 1.26 · linux debian/x64 · docker and passed.
sha256:ab0abfc17d320bebb00ce8b34ee15f99699b481e8615a916e62f8bb9001ea795
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
linux 24 · ubuntu · glibc 2.39 x64 go
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-09-10 |
Case
HOW- Goal
- verify pkg:golang/github.com/klauspost/compress@v1.19.1
- Created
- 2026-09-10T21:10:34Z
Contract
- zstd.NewWriter compresses data stream and zstd.NewReader decompresses back to exact original payload
- zstd.NewWriter compresses with various encoder speed levels including SpeedFastest and SpeedBestCompression
- zstd.NewReader returns error when reading invalid or corrupted zstd stream
- zstd.NewWriter and zstd.NewReader correctly roundtrip empty payload
- zstd.NewWriter and zstd.NewReader support stream reuse via Reset
- compress.Estimate distinguishes compressible repetitive bytes from incompressible data
Files
- PROMPT.md
- compress.go
- csx.json
- go.mod
- go.sum
- spec.json
- test/contract.go
Source
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify pkg:golang/github.com/klauspost/compress@v1.19.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/klauspost/compress@v1.19.1
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
package sample
import (
"bytes"
"fmt"
"io"
"github.com/klauspost/compress"
"github.com/klauspost/compress/zstd"
)
// Compress compresses data using zstd default settings.
func Compress(src []byte) ([]byte, error) {
var buf bytes.Buffer
w, err := zstd.NewWriter(&buf)
if err != nil {
return nil, fmt.Errorf("create zstd writer: %w", err)
}
if _, err := w.Write(src); err != nil {
_ = w.Close()
return nil, fmt.Errorf("write zstd: %w", err)
}
if err := w.Close(); err != nil {
return nil, fmt.Errorf("close zstd writer: %w", err)
}
return buf.Bytes(), nil
}
// CompressWithLevel compresses data using zstd with a specific encoder level.
func CompressWithLevel(src []byte, level zstd.EncoderLevel) ([]byte, error) {
var buf bytes.Buffer
w, err := zstd.NewWriter(&buf, zstd.WithEncoderLevel(level))
if err != nil {
return nil, fmt.Errorf("create zstd writer with level: %w", err)
}
if _, err := w.Write(src); err != nil {
_ = w.Close()
return nil, fmt.Errorf("write zstd: %w", err)
}
if err := w.Close(); err != nil {
return nil, fmt.Errorf("close zstd writer: %w", err)
}
return buf.Bytes(), nil
}
// Decompress decompresses zstd compressed data using zstd.NewReader.
func Decompress(src []byte) ([]byte, error) {
r, err := zstd.NewReader(bytes.NewReader(src))
if err != nil {
return nil, fmt.Errorf("create zstd reader: %w", err)
}
defer r.Close()
decompressed, err := io.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("read zstd: %w", err)
}
return decompressed, nil
}
// EstimateCompressibility returns compressibility estimate using compress.Estimate.
func EstimateCompressibility(data []byte) float64 {
return compress.Estimate(data)
}
{"case":{"caseId":"case:sha256:5e8f5e01ce0b406550d0f14b5873f207466c3cea11bfdf4df8ee48fc5713098b","contract":["zstd.NewWriter compresses data stream and zstd.NewReader decompresses back to exact original payload","zstd.NewWriter compresses with various encoder speed levels including SpeedFastest and SpeedBestCompression","zstd.NewReader returns error when reading invalid or corrupted zstd stream","zstd.NewWriter and zstd.NewReader correctly roundtrip empty payload","zstd.NewWriter and zstd.NewReader support stream reuse via Reset","compress.Estimate distinguishes compressible repetitive bytes from incompressible data"],"goal":"verify pkg:golang/github.com/klauspost/compress@v1.19.1","kind":"HOW","packages":["pkg:golang/github.com/klauspost/compress@v1.19.1"],"schemaVersion":1},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/klauspost/compress@v1.19.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/klauspost/compress@v1.19.1","verifierAdapter":"golang@1"}
module sample
go 1.26.6
require github.com/klauspost/compress v1.19.1
github.com/klauspost/compress v1.19.1 h1:VsB4HPswih7mmZ8WleSFQ75c/Ui1M4trX5oAsJnhSlk=
github.com/klauspost/compress v1.19.1/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
{
"schemaVersion": 1,
"goal": "verify pkg:golang/github.com/klauspost/compress@v1.19.1",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/klauspost/compress@v1.19.1"
]
}
package main
import (
"bytes"
"fmt"
"io"
"os"
"github.com/klauspost/compress"
"github.com/klauspost/compress/zstd"
"sample"
)
func main() {
// Assertion 1: zstd.NewWriter compresses data stream and zstd.NewReader decompresses back to exact original payload
original := []byte("The quick brown fox jumps over the lazy dog - testing klauspost/compress zstd roundtrip")
compressed, err := sample.Compress(original)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Compress failed: %v\n", err)
os.Exit(1)
}
decompressed, err := sample.Decompress(compressed)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Decompress failed: %v\n", err)
os.Exit(1)
}
if !bytes.Equal(decompressed, original) {
fmt.Fprintf(os.Stderr, "FAIL: decompressed payload mismatch: got %q, want %q\n", decompressed, original)
os.Exit(1)
}
// Assertion 2: zstd.NewWriter compresses with various encoder speed levels including SpeedFastest and SpeedBestCompression
levels := []zstd.EncoderLevel{
zstd.SpeedFastest,
zstd.SpeedDefault,
zstd.SpeedBetterCompression,
zstd.SpeedBestCompression,
}
for _, lvl := range levels {
compLevel, err := sample.CompressWithLevel(original, lvl)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: CompressWithLevel failed for level %v: %v\n", lvl, err)
os.Exit(1)
}
decompLevel, err := sample.Decompress(compLevel)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Decompress for level %v failed: %v\n", lvl, err)
os.Exit(1)
}
if !bytes.Equal(decompLevel, original) {
fmt.Fprintf(os.Stderr, "FAIL: decompressed mismatch for level %v: got %q, want %q\n", lvl, decompLevel, original)
os.Exit(1)
}
}
// Assertion 3: zstd.NewReader returns error when reading invalid or corrupted zstd stream
corrupt := []byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}
r, err := zstd.NewReader(bytes.NewReader(corrupt))
if err == nil {
_, readErr := io.ReadAll(r)
r.Close()
if readErr == nil {
fmt.Fprintf(os.Stderr, "FAIL: expected error reading corrupt data, got nil\n")
os.Exit(1)
}
}
// Assertion 4: zstd.NewWriter and zstd.NewReader correctly roundtrip empty payload
emptyComp, err := sample.Compress([]byte{})
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Compress empty failed: %v\n", err)
os.Exit(1)
}
emptyDecomp, err := sample.Decompress(emptyComp)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Decompress empty failed: %v\n", err)
os.Exit(1)
}
if len(emptyDecomp) != 0 {
fmt.Fprintf(os.Stderr, "FAIL: expected empty decompressed slice, got %d bytes\n", len(emptyDecomp))
os.Exit(1)
}
// Assertion 5: zstd.NewWriter and zstd.NewReader support stream reuse via Reset
payloadA := []byte("Stream A data for reusable writer and reader")
payloadB := []byte("Stream B data confirming successful reset of encoder and decoder")
var buf bytes.Buffer
enc, err := zstd.NewWriter(&buf)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: NewWriter for Reset failed: %v\n", err)
os.Exit(1)
}
if _, err := enc.Write(payloadA); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: enc.Write payloadA failed: %v\n", err)
os.Exit(1)
}
if err := enc.Close(); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: enc.Close payloadA failed: %v\n", err)
os.Exit(1)
}
compA := make([]byte, buf.Len())
copy(compA, buf.Bytes())
buf.Reset()
enc.Reset(&buf)
if _, err := enc.Write(payloadB); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: enc.Write payloadB failed: %v\n", err)
os.Exit(1)
}
if err := enc.Close(); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: enc.Close payloadB failed: %v\n", err)
os.Exit(1)
}
compB := buf.Bytes()
dec, err := zstd.NewReader(bytes.NewReader(compA))
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: NewReader for payloadA failed: %v\n", err)
os.Exit(1)
}
outA, err := io.ReadAll(dec)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: ReadAll outA failed: %v\n", err)
os.Exit(1)
}
if !bytes.Equal(outA, payloadA) {
fmt.Fprintf(os.Stderr, "FAIL: outA mismatch: got %q, want %q\n", outA, payloadA)
os.Exit(1)
}
if err := dec.Reset(bytes.NewReader(compB)); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: dec.Reset failed: %v\n", err)
os.Exit(1)
}
outB, err := io.ReadAll(dec)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: ReadAll outB failed: %v\n", err)
os.Exit(1)
}
if !bytes.Equal(outB, payloadB) {
fmt.Fprintf(os.Stderr, "FAIL: outB mismatch: got %q, want %q\n", outB, payloadB)
os.Exit(1)
}
dec.Close()
// Assertion 6: compress.Estimate distinguishes compressible repetitive bytes from incompressible data
repetitive := bytes.Repeat([]byte("repeating pattern of characters "), 10)
randomLike := make([]byte, 256)
for i := range randomLike {
randomLike[i] = byte((i*107 + 53) % 256)
}
estRepetitive := compress.Estimate(repetitive)
estRandom := compress.Estimate(randomLike)
if estRepetitive <= estRandom {
fmt.Fprintf(os.Stderr, "FAIL: expected repetitive estimate (%f) > random estimate (%f)\n", estRepetitive, estRandom)
os.Exit(1)
}
fmt.Println("PASS: pkg:golang/github.com/klauspost/compress@v1.19.1 contract passed")
}
Origin Seeder
anonymous