Sample
github.com/klauspost/compress v1.20.0: zlib.NewWriter
Verified sample for golang github.com/klauspost/compress v1.20.0: zlib.NewWriter. The contract ran on go 1.26 · linux debian/x64 · docker and passed.
sha256:51f9d3ab43a6628ebf640ec0201c003f754e24a1f9063751636b63c6d8e671bd
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-03 |
Case
HOW- Goal
- verify github.com/klauspost/compress/zlib.NewWriter in pkg:golang/github.com/klauspost/compress@v1.20.0
- Symbols
-
- github.com/klauspost/compress/zlib.NewWriter
- Created
- 2026-09-03T00:01:16Z
Contract
- zlib.NewWriter writes compressed data stream that decompresses to match original uncompressed bytes
- zlib.NewWriterLevel initializes a writer with specified compression levels including BestSpeed and BestCompression
- zlib.NewWriter handles empty input buffers and emits a valid zlib stream on Close
- zlib.NewWriter Flush flushes pending compressed data to the underlying writer
- zlib.NewWriter Reset reinitializes the writer to write to a new destination without reallocating state
- zlib.NewWriterLevelDict initializes a writer with a custom dictionary and compresses data successfully
Files
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- 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 github.com/klauspost/compress/zlib.NewWriter in pkg:golang/github.com/klauspost/compress@v1.20.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/klauspost/compress@v1.20.0
Demonstrate these symbols/APIs:
- github.com/klauspost/compress/zlib.NewWriter
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.
{"case":{"caseId":"case:sha256:3c5d6b18db06e8be308758d0703cfe16a9379930d228ff3c0f1caffe806b2e42","contract":["zlib.NewWriter writes compressed data stream that decompresses to match original uncompressed bytes","zlib.NewWriterLevel initializes a writer with specified compression levels including BestSpeed and BestCompression","zlib.NewWriter handles empty input buffers and emits a valid zlib stream on Close","zlib.NewWriter Flush flushes pending compressed data to the underlying writer","zlib.NewWriter Reset reinitializes the writer to write to a new destination without reallocating state","zlib.NewWriterLevelDict initializes a writer with a custom dictionary and compresses data successfully"],"goal":"verify github.com/klauspost/compress/zlib.NewWriter in pkg:golang/github.com/klauspost/compress@v1.20.0","kind":"HOW","packages":["pkg:golang/github.com/klauspost/compress@v1.20.0"],"schemaVersion":1,"symbols":["github.com/klauspost/compress/zlib.NewWriter"]},"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.20.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/klauspost/compress@v1.20.0","symbols":["github.com/klauspost/compress/zlib.NewWriter"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.6
require github.com/klauspost/compress v1.20.0
github.com/klauspost/compress v1.20.0 h1:a3C1ke2ohxFymNlb2HWAHjDeKCI90scRskErZkR0ezA=
github.com/klauspost/compress v1.20.0/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
package main
import (
"bytes"
"fmt"
"io"
"log"
"github.com/klauspost/compress/zlib"
)
func main() {
input := []byte("Demonstrating zlib.NewWriter compression with github.com/klauspost/compress.")
var compressedBuf bytes.Buffer
writer := zlib.NewWriter(&compressedBuf)
if _, err := writer.Write(input); err != nil {
log.Fatalf("failed to write compressed data: %v", err)
}
if err := writer.Close(); err != nil {
log.Fatalf("failed to close zlib writer: %v", err)
}
reader, err := zlib.NewReader(&compressedBuf)
if err != nil {
log.Fatalf("failed to open zlib reader: %v", err)
}
defer reader.Close()
decompressed, err := io.ReadAll(reader)
if err != nil {
log.Fatalf("failed to read decompressed data: %v", err)
}
fmt.Printf("Original: %s\n", string(input))
fmt.Printf("Decompressed: %s\n", string(decompressed))
}
{
"schemaVersion": 1,
"goal": "verify github.com/klauspost/compress/zlib.NewWriter in pkg:golang/github.com/klauspost/compress@v1.20.0",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/klauspost/compress@v1.20.0"
],
"symbols": [
"github.com/klauspost/compress/zlib.NewWriter"
]
}
package main
import (
"bytes"
"fmt"
"io"
"os"
"github.com/klauspost/compress/zlib"
)
func main() {
// 1. zlib.NewWriter writes compressed data stream that decompresses to match original uncompressed bytes
{
original := []byte("CodeSampleX contract verification: klauspost/compress/zlib.NewWriter standard stream roundtrip test.")
var buf bytes.Buffer
zw := zlib.NewWriter(&buf)
if _, err := zw.Write(original); err != nil {
fmt.Fprintf(os.Stderr, "zlib.NewWriter Write error: %v\n", err)
os.Exit(1)
}
if err := zw.Close(); err != nil {
fmt.Fprintf(os.Stderr, "zlib.NewWriter Close error: %v\n", err)
os.Exit(1)
}
zr, err := zlib.NewReader(&buf)
if err != nil {
fmt.Fprintf(os.Stderr, "zlib.NewReader error: %v\n", err)
os.Exit(1)
}
decompressed, err := io.ReadAll(zr)
if err != nil {
fmt.Fprintf(os.Stderr, "zlib.NewReader ReadAll error: %v\n", err)
os.Exit(1)
}
if err := zr.Close(); err != nil {
fmt.Fprintf(os.Stderr, "zlib.NewReader Close error: %v\n", err)
os.Exit(1)
}
if !bytes.Equal(original, decompressed) {
fmt.Fprintf(os.Stderr, "decompressed payload mismatch: got %q, want %q\n", string(decompressed), string(original))
os.Exit(1)
}
}
// 2. zlib.NewWriterLevel initializes a writer with specified compression levels including BestSpeed and BestCompression
{
sampleData := bytes.Repeat([]byte("Evaluating compression ratio and integrity across distinct zlib compression levels. "), 30)
levels := []int{
zlib.NoCompression,
zlib.BestSpeed,
zlib.DefaultCompression,
zlib.BestCompression,
zlib.HuffmanOnly,
}
for _, lvl := range levels {
var buf bytes.Buffer
zw, err := zlib.NewWriterLevel(&buf, lvl)
if err != nil {
fmt.Fprintf(os.Stderr, "zlib.NewWriterLevel(%d) error: %v\n", lvl, err)
os.Exit(1)
}
if _, err := zw.Write(sampleData); err != nil {
fmt.Fprintf(os.Stderr, "zw.Write with level %d error: %v\n", lvl, err)
os.Exit(1)
}
if err := zw.Close(); err != nil {
fmt.Fprintf(os.Stderr, "zw.Close with level %d error: %v\n", lvl, err)
os.Exit(1)
}
zr, err := zlib.NewReader(&buf)
if err != nil {
fmt.Fprintf(os.Stderr, "zlib.NewReader with level %d error: %v\n", lvl, err)
os.Exit(1)
}
decomp, err := io.ReadAll(zr)
if err != nil {
fmt.Fprintf(os.Stderr, "zlib.NewReader ReadAll with level %d error: %v\n", lvl, err)
os.Exit(1)
}
if err := zr.Close(); err != nil {
fmt.Fprintf(os.Stderr, "zlib.NewReader Close with level %d error: %v\n", lvl, err)
os.Exit(1)
}
if !bytes.Equal(sampleData, decomp) {
fmt.Fprintf(os.Stderr, "level %d roundtrip mismatch\n", lvl)
os.Exit(1)
}
}
}
// 3. zlib.NewWriter handles empty input buffers and emits a valid zlib stream on Close
{
var buf bytes.Buffer
zw := zlib.NewWriter(&buf)
if err := zw.Close(); err != nil {
fmt.Fprintf(os.Stderr, "empty zlib.NewWriter Close error: %v\n", err)
os.Exit(1)
}
if buf.Len() == 0 {
fmt.Fprintf(os.Stderr, "expected zlib header and footer for empty stream, got 0 bytes\n")
os.Exit(1)
}
zr, err := zlib.NewReader(&buf)
if err != nil {
fmt.Fprintf(os.Stderr, "empty stream zlib.NewReader error: %v\n", err)
os.Exit(1)
}
out, err := io.ReadAll(zr)
if err != nil {
fmt.Fprintf(os.Stderr, "empty stream ReadAll error: %v\n", err)
os.Exit(1)
}
if err := zr.Close(); err != nil {
fmt.Fprintf(os.Stderr, "empty stream zr.Close error: %v\n", err)
os.Exit(1)
}
if len(out) != 0 {
fmt.Fprintf(os.Stderr, "expected 0 decompressed bytes, got %d\n", len(out))
os.Exit(1)
}
}
// 4. zlib.NewWriter Flush flushes pending compressed data to the underlying writer
{
var buf bytes.Buffer
zw := zlib.NewWriter(&buf)
msg := []byte("buffered message for verifying intermediate Flush operation")
if _, err := zw.Write(msg); err != nil {
fmt.Fprintf(os.Stderr, "Flush test Write error: %v\n", err)
os.Exit(1)
}
if err := zw.Flush(); err != nil {
fmt.Fprintf(os.Stderr, "zw.Flush error: %v\n", err)
os.Exit(1)
}
if buf.Len() == 0 {
fmt.Fprintf(os.Stderr, "expected flushed bytes in underlying buffer, got 0\n")
os.Exit(1)
}
if err := zw.Close(); err != nil {
fmt.Fprintf(os.Stderr, "zw.Close after flush error: %v\n", err)
os.Exit(1)
}
zr, err := zlib.NewReader(&buf)
if err != nil {
fmt.Fprintf(os.Stderr, "zlib.NewReader after Flush error: %v\n", err)
os.Exit(1)
}
decomp, err := io.ReadAll(zr)
if err != nil || !bytes.Equal(decomp, msg) {
fmt.Fprintf(os.Stderr, "flushed stream decomp mismatch: %v\n", err)
os.Exit(1)
}
_ = zr.Close()
}
// 5. zlib.NewWriter Reset reinitializes the writer to write to a new destination without reallocating state
{
var buf1, buf2 bytes.Buffer
zw := zlib.NewWriter(&buf1)
p1 := []byte("first stream payload for reset verification")
if _, err := zw.Write(p1); err != nil {
fmt.Fprintf(os.Stderr, "reset test stream 1 write error: %v\n", err)
os.Exit(1)
}
if err := zw.Close(); err != nil {
fmt.Fprintf(os.Stderr, "reset test stream 1 close error: %v\n", err)
os.Exit(1)
}
zw.Reset(&buf2)
p2 := []byte("second stream payload written after reset invocation")
if _, err := zw.Write(p2); err != nil {
fmt.Fprintf(os.Stderr, "reset test stream 2 write error: %v\n", err)
os.Exit(1)
}
if err := zw.Close(); err != nil {
fmt.Fprintf(os.Stderr, "reset test stream 2 close error: %v\n", err)
os.Exit(1)
}
zr1, err := zlib.NewReader(&buf1)
if err != nil {
fmt.Fprintf(os.Stderr, "reader 1 init error: %v\n", err)
os.Exit(1)
}
out1, err := io.ReadAll(zr1)
if err != nil || !bytes.Equal(out1, p1) {
fmt.Fprintf(os.Stderr, "out1 mismatch: %v\n", err)
os.Exit(1)
}
_ = zr1.Close()
zr2, err := zlib.NewReader(&buf2)
if err != nil {
fmt.Fprintf(os.Stderr, "reader 2 init error: %v\n", err)
os.Exit(1)
}
out2, err := io.ReadAll(zr2)
if err != nil || !bytes.Equal(out2, p2) {
fmt.Fprintf(os.Stderr, "out2 mismatch: %v\n", err)
os.Exit(1)
}
_ = zr2.Close()
}
// 6. zlib.NewWriterLevelDict initializes a writer with a custom dictionary and compresses data successfully
{
dict := []byte("specialized terminology dictionary tokens keys values protocol")
payload := []byte("specialized terminology dictionary protocol message with repeating dictionary words")
var buf bytes.Buffer
zwDict, err := zlib.NewWriterLevelDict(&buf, zlib.DefaultCompression, dict)
if err != nil {
fmt.Fprintf(os.Stderr, "zlib.NewWriterLevelDict error: %v\n", err)
os.Exit(1)
}
if _, err := zwDict.Write(payload); err != nil {
fmt.Fprintf(os.Stderr, "zwDict.Write error: %v\n", err)
os.Exit(1)
}
if err := zwDict.Close(); err != nil {
fmt.Fprintf(os.Stderr, "zwDict.Close error: %v\n", err)
os.Exit(1)
}
zrDict, err := zlib.NewReaderDict(&buf, dict)
if err != nil {
fmt.Fprintf(os.Stderr, "zlib.NewReaderDict error: %v\n", err)
os.Exit(1)
}
decompDict, err := io.ReadAll(zrDict)
if err != nil {
fmt.Fprintf(os.Stderr, "zrDict ReadAll error: %v\n", err)
os.Exit(1)
}
if err := zrDict.Close(); err != nil {
fmt.Fprintf(os.Stderr, "zrDict Close error: %v\n", err)
os.Exit(1)
}
if !bytes.Equal(payload, decompDict) {
fmt.Fprintf(os.Stderr, "dict decompression mismatch: got %q, want %q\n", string(decompDict), string(payload))
os.Exit(1)
}
}
fmt.Println("All contract assertions passed.")
}
Origin Seeder
anonymous