CodeSampleX

Sample

github.com/klauspost/compress v1.19.1: zlib.HuffmanOnly

Verified sample for golang github.com/klauspost/compress v1.19.1: zlib.HuffmanOnly. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:6088b6cbe82346058be13b665a75a746fa4b64b66852aaa7aa322262d806ece0

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-10-11

Case

HOW
Goal
verify github.com/klauspost/compress/zlib.HuffmanOnly in pkg:golang/github.com/klauspost/compress@v1.19.1
Packages
Symbols
  • github.com/klauspost/compress/zlib.HuffmanOnly
Created
2026-10-11T08:04:03Z

Contract

  1. zlib.HuffmanOnly is defined as compression level constant -2
  2. zlib.NewWriterLevel accepts zlib.HuffmanOnly and compresses data that roundtrips through zlib.NewReader
  3. zlib.NewWriterLevelDict accepts zlib.HuffmanOnly and preset dictionary to compress and decompress data
  4. zlib.NewWriterLevel with zlib.HuffmanOnly supports Reset to compress multiple consecutive streams
  5. zlib.NewWriterLevel with zlib.HuffmanOnly emits valid zlib stream header and trailer for empty payloads
  6. zlib.NewWriterLevel with zlib.HuffmanOnly flushes pending compressed bytes to destination on Flush

Files

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

Download the source artifact (tar.gz)

Source

PROMPT.md
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.HuffmanOnly in 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
Demonstrate these symbols/APIs:
  - github.com/klauspost/compress/zlib.HuffmanOnly

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.
csx.json
{"case":{"caseId":"case:sha256:9abe3af253c7e1959590647c84e57f545fcd1172ce03784019a024965a79dbd2","contract":["zlib.HuffmanOnly is defined as compression level constant -2","zlib.NewWriterLevel accepts zlib.HuffmanOnly and compresses data that roundtrips through zlib.NewReader","zlib.NewWriterLevelDict accepts zlib.HuffmanOnly and preset dictionary to compress and decompress data","zlib.NewWriterLevel with zlib.HuffmanOnly supports Reset to compress multiple consecutive streams","zlib.NewWriterLevel with zlib.HuffmanOnly emits valid zlib stream header and trailer for empty payloads","zlib.NewWriterLevel with zlib.HuffmanOnly flushes pending compressed bytes to destination on Flush"],"goal":"verify github.com/klauspost/compress/zlib.HuffmanOnly in pkg:golang/github.com/klauspost/compress@v1.19.1","kind":"HOW","packages":["pkg:golang/github.com/klauspost/compress@v1.19.1"],"schemaVersion":1,"symbols":["github.com/klauspost/compress/zlib.HuffmanOnly"]},"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","symbols":["github.com/klauspost/compress/zlib.HuffmanOnly"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/klauspost/compress v1.19.1
go.sum
github.com/klauspost/compress v1.19.1 h1:VsB4HPswih7mmZ8WleSFQ75c/Ui1M4trX5oAsJnhSlk=
github.com/klauspost/compress v1.19.1/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
main.go
package main

import (
	"bytes"
	"fmt"
	"io"
	"log"

	"github.com/klauspost/compress/zlib"
)

func main() {
	input := []byte("Hello, CodeSampleX! Verifying HuffmanOnly compression mode.")

	// Compress data using zlib.HuffmanOnly
	var compressed bytes.Buffer
	writer, err := zlib.NewWriterLevel(&compressed, zlib.HuffmanOnly)
	if err != nil {
		log.Fatalf("failed to create zlib writer with HuffmanOnly: %v", err)
	}

	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)
	}

	// Decompress data using zlib.NewReader
	reader, err := zlib.NewReader(&compressed)
	if err != nil {
		log.Fatalf("failed to create 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))
	fmt.Printf("HuffmanOnly level value: %d\n", zlib.HuffmanOnly)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/klauspost/compress/zlib.HuffmanOnly in pkg:golang/github.com/klauspost/compress@v1.19.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/klauspost/compress@v1.19.1"
  ],
  "symbols": [
    "github.com/klauspost/compress/zlib.HuffmanOnly"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"io"
	"os"

	"github.com/klauspost/compress/zlib"
)

func main() {
	if err := runContractTests(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("All contract tests passed successfully.")
}

func runContractTests() error {
	// 1. zlib.HuffmanOnly is defined as compression level constant -2
	{
		if zlib.HuffmanOnly != -2 {
			return fmt.Errorf("expected zlib.HuffmanOnly to be -2, got %d", zlib.HuffmanOnly)
		}
	}

	// 2. zlib.NewWriterLevel accepts zlib.HuffmanOnly and compresses data that roundtrips through zlib.NewReader
	{
		original := bytes.Repeat([]byte("HuffmanOnly entropy encoding test payload without string matching. "), 40)
		var buf bytes.Buffer
		zw, err := zlib.NewWriterLevel(&buf, zlib.HuffmanOnly)
		if err != nil {
			return fmt.Errorf("zlib.NewWriterLevel with HuffmanOnly failed: %w", err)
		}
		if _, err := zw.Write(original); err != nil {
			return fmt.Errorf("zw.Write failed: %w", err)
		}
		if err := zw.Close(); err != nil {
			return fmt.Errorf("zw.Close failed: %w", err)
		}

		zr, err := zlib.NewReader(&buf)
		if err != nil {
			return fmt.Errorf("zlib.NewReader failed: %w", err)
		}
		decompressed, err := io.ReadAll(zr)
		if err != nil {
			return fmt.Errorf("zr ReadAll failed: %w", err)
		}
		if err := zr.Close(); err != nil {
			return fmt.Errorf("zr.Close failed: %w", err)
		}
		if !bytes.Equal(original, decompressed) {
			return fmt.Errorf("roundtrip data mismatch with HuffmanOnly")
		}
	}

	// 3. zlib.NewWriterLevelDict accepts zlib.HuffmanOnly and preset dictionary to compress and decompress data
	{
		dict := []byte("common-dictionary-prefix-for-testing-huffman-only")
		payload := []byte("common-dictionary-prefix-for-testing-huffman-only and unique suffix data")
		var buf bytes.Buffer
		zw, err := zlib.NewWriterLevelDict(&buf, zlib.HuffmanOnly, dict)
		if err != nil {
			return fmt.Errorf("zlib.NewWriterLevelDict with HuffmanOnly failed: %w", err)
		}
		if _, err := zw.Write(payload); err != nil {
			return fmt.Errorf("zw.Write with dict failed: %w", err)
		}
		if err := zw.Close(); err != nil {
			return fmt.Errorf("zw.Close with dict failed: %w", err)
		}

		zr, err := zlib.NewReaderDict(&buf, dict)
		if err != nil {
			return fmt.Errorf("zlib.NewReaderDict failed: %w", err)
		}
		decompressed, err := io.ReadAll(zr)
		if err != nil {
			return fmt.Errorf("zr ReadAll with dict failed: %w", err)
		}
		if err := zr.Close(); err != nil {
			return fmt.Errorf("zr.Close with dict failed: %w", err)
		}
		if !bytes.Equal(payload, decompressed) {
			return fmt.Errorf("dictionary roundtrip mismatch with HuffmanOnly")
		}
	}

	// 4. zlib.NewWriterLevel with zlib.HuffmanOnly supports Reset to compress multiple consecutive streams
	{
		data1 := []byte("first stream data compressed with HuffmanOnly")
		data2 := []byte("second stream data compressed after Reset with HuffmanOnly")

		var buf1 bytes.Buffer
		zw, err := zlib.NewWriterLevel(&buf1, zlib.HuffmanOnly)
		if err != nil {
			return fmt.Errorf("zlib.NewWriterLevel failed: %w", err)
		}
		if _, err := zw.Write(data1); err != nil {
			return fmt.Errorf("stream 1 write failed: %w", err)
		}
		if err := zw.Close(); err != nil {
			return fmt.Errorf("stream 1 close failed: %w", err)
		}

		var buf2 bytes.Buffer
		zw.Reset(&buf2)
		if _, err := zw.Write(data2); err != nil {
			return fmt.Errorf("stream 2 write failed: %w", err)
		}
		if err := zw.Close(); err != nil {
			return fmt.Errorf("stream 2 close failed: %w", err)
		}

		// Verify stream 1
		zr1, err := zlib.NewReader(&buf1)
		if err != nil {
			return fmt.Errorf("stream 1 reader failed: %w", err)
		}
		out1, err := io.ReadAll(zr1)
		if err != nil || !bytes.Equal(out1, data1) {
			return fmt.Errorf("stream 1 content mismatch after Reset")
		}
		_ = zr1.Close()

		// Verify stream 2
		zr2, err := zlib.NewReader(&buf2)
		if err != nil {
			return fmt.Errorf("stream 2 reader failed: %w", err)
		}
		out2, err := io.ReadAll(zr2)
		if err != nil || !bytes.Equal(out2, data2) {
			return fmt.Errorf("stream 2 content mismatch after Reset")
		}
		_ = zr2.Close()
	}

	// 5. zlib.NewWriterLevel with zlib.HuffmanOnly emits valid zlib stream header and trailer for empty payloads
	{
		var buf bytes.Buffer
		zw, err := zlib.NewWriterLevel(&buf, zlib.HuffmanOnly)
		if err != nil {
			return fmt.Errorf("empty stream writer creation failed: %w", err)
		}
		if err := zw.Close(); err != nil {
			return fmt.Errorf("empty stream close failed: %w", err)
		}
		if buf.Len() == 0 {
			return fmt.Errorf("expected non-empty zlib header/trailer for empty stream, got 0 bytes")
		}

		zr, err := zlib.NewReader(&buf)
		if err != nil {
			return fmt.Errorf("empty stream reader creation failed: %w", err)
		}
		out, err := io.ReadAll(zr)
		if err != nil {
			return fmt.Errorf("empty stream ReadAll failed: %w", err)
		}
		if err := zr.Close(); err != nil {
			return fmt.Errorf("empty stream reader close failed: %w", err)
		}
		if len(out) != 0 {
			return fmt.Errorf("expected 0 decompressed bytes for empty stream, got %d", len(out))
		}
	}

	// 6. zlib.NewWriterLevel with zlib.HuffmanOnly flushes pending compressed bytes to destination on Flush
	{
		var buf bytes.Buffer
		zw, err := zlib.NewWriterLevel(&buf, zlib.HuffmanOnly)
		if err != nil {
			return fmt.Errorf("flush test writer creation failed: %w", err)
		}
		msg := []byte("flush test payload to verify intermediate buffer flushing with HuffmanOnly")
		if _, err := zw.Write(msg); err != nil {
			return fmt.Errorf("flush write failed: %w", err)
		}
		if err := zw.Flush(); err != nil {
			return fmt.Errorf("Flush() failed: %w", err)
		}
		if buf.Len() == 0 {
			return fmt.Errorf("expected non-zero bytes in buffer after Flush(), got 0")
		}
		if err := zw.Close(); err != nil {
			return fmt.Errorf("flush test close failed: %w", err)
		}

		zr, err := zlib.NewReader(&buf)
		if err != nil {
			return fmt.Errorf("reader after flush failed: %w", err)
		}
		decomp, err := io.ReadAll(zr)
		if err != nil || !bytes.Equal(decomp, msg) {
			return fmt.Errorf("flush roundtrip payload mismatch")
		}
		_ = zr.Close()
	}

	return nil
}

Origin Seeder

anonymous