CodeSampleX

Beispiel

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

Verifiziertes Beispiel für golang github.com/klauspost/compress v1.19.1: zlib.NewReaderDict. Der Vertrag lief auf go 1.26 · linux debian/x64 · docker und…

sha256:1326ef7c20d3b23ec164dfb0c3faf525dc5a866a4233f1ade67a69163d387404

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung go 1.26 linux 24 · ubuntu · glibc 2.39 amd64 go 1.26 go 1.26 go 1

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify github.com/klauspost/compress/zlib.NewReaderDict in pkg:golang/github.com/klauspost/compress@v1.19.1
Pakete
Symbole
  • github.com/klauspost/compress/zlib.NewReaderDict
Umgebung
go 1.26.6
Erstellt
2026-10-11T06:58:16Z

Contract

  1. NewReaderDict successfully decompresses data compressed with a matching preset dictionary
  2. NewReaderDict returns ErrDictionary when the compressed data requires a different preset dictionary
  3. NewReaderDict decompresses standard zlib streams without a dictionary when nil dict is provided
  4. NewReaderDict returns ErrHeader when provided invalid zlib header bytes
  5. NewReaderDict returns an io.ReadCloser that implements the Resetter interface for reusing the decompressor

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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.NewReaderDict 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.NewReaderDict

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:3f04228853406251d569367cd9dc06fd22c66cdd40d95f01076410e99a782e85","contract":["NewReaderDict successfully decompresses data compressed with a matching preset dictionary","NewReaderDict returns ErrDictionary when the compressed data requires a different preset dictionary","NewReaderDict decompresses standard zlib streams without a dictionary when nil dict is provided","NewReaderDict returns ErrHeader when provided invalid zlib header bytes","NewReaderDict returns an io.ReadCloser that implements the Resetter interface for reusing the decompressor"],"goal":"verify github.com/klauspost/compress/zlib.NewReaderDict 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.NewReaderDict"]},"contractCommand":["go","run","./test"],"environment":{"arch":"amd64","compiler":"go","compilerVersion":"1.26.6","distro":"ubuntu","ecosystem":"golang","language":"go","languageVersion":"1.26.6","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","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.NewReaderDict"],"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"
	"os"

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

func main() {
	dict := []byte("shared-zlib-preset-dictionary")
	rawMessage := []byte("Demonstrating zlib decompression with preset dictionary using klauspost/compress")

	var buf bytes.Buffer
	writer, err := zlib.NewWriterLevelDict(&buf, zlib.DefaultCompression, dict)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to create zlib writer: %v\n", err)
		os.Exit(1)
	}
	if _, err := writer.Write(rawMessage); err != nil {
		fmt.Fprintf(os.Stderr, "failed to write data: %v\n", err)
		os.Exit(1)
	}
	if err := writer.Close(); err != nil {
		fmt.Fprintf(os.Stderr, "failed to close writer: %v\n", err)
		os.Exit(1)
	}

	reader, err := zlib.NewReaderDict(&buf, dict)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to create zlib reader with dict: %v\n", err)
		os.Exit(1)
	}
	defer reader.Close()

	decompressed, err := io.ReadAll(reader)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to read decompressed data: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("Successfully decompressed %d bytes: %s\n", len(decompressed), string(decompressed))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/klauspost/compress/zlib.NewReaderDict 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.NewReaderDict"
  ]
}
test/contract.go
package main

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

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

func main() {
	// Assertion 1: NewReaderDict successfully decompresses data compressed with a matching preset dictionary
	{
		dict := []byte("contract-test-dictionary-preset-12345")
		original := []byte("The quick brown fox jumps over the lazy dog. Zlib compression with dictionary verification.")

		var buf bytes.Buffer
		w, err := zlib.NewWriterLevelDict(&buf, zlib.DefaultCompression, dict)
		if err != nil {
			fmt.Fprintf(os.Stderr, "assertion 1 setup failed: NewWriterLevelDict: %v\n", err)
			os.Exit(1)
		}
		if _, err := w.Write(original); err != nil {
			fmt.Fprintf(os.Stderr, "assertion 1 setup failed: Write: %v\n", err)
			os.Exit(1)
		}
		if err := w.Close(); err != nil {
			fmt.Fprintf(os.Stderr, "assertion 1 setup failed: Close: %v\n", err)
			os.Exit(1)
		}

		r, err := zlib.NewReaderDict(&buf, dict)
		if err != nil {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: NewReaderDict returned error: %v\n", err)
			os.Exit(1)
		}

		decompressed, err := io.ReadAll(r)
		if err != nil {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: io.ReadAll returned error: %v\n", err)
			os.Exit(1)
		}
		if err := r.Close(); err != nil {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: r.Close returned error: %v\n", err)
			os.Exit(1)
		}

		if !bytes.Equal(decompressed, original) {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: decompressed data does not match original\n")
			os.Exit(1)
		}
	}

	// Assertion 2: NewReaderDict returns ErrDictionary when the compressed data requires a different preset dictionary
	{
		dictA := []byte("dictionary-alpha-key-spec")
		dictB := []byte("dictionary-beta-different-key")
		payload := []byte("Payload compressed with dictionary alpha.")

		var buf bytes.Buffer
		w, err := zlib.NewWriterLevelDict(&buf, zlib.DefaultCompression, dictA)
		if err != nil {
			fmt.Fprintf(os.Stderr, "assertion 2 setup failed: NewWriterLevelDict: %v\n", err)
			os.Exit(1)
		}
		if _, err := w.Write(payload); err != nil {
			fmt.Fprintf(os.Stderr, "assertion 2 setup failed: Write: %v\n", err)
			os.Exit(1)
		}
		if err := w.Close(); err != nil {
			fmt.Fprintf(os.Stderr, "assertion 2 setup failed: Close: %v\n", err)
			os.Exit(1)
		}

		_, err = zlib.NewReaderDict(&buf, dictB)
		if !errors.Is(err, zlib.ErrDictionary) {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: expected ErrDictionary, got: %v\n", err)
			os.Exit(1)
		}
	}

	// Assertion 3: NewReaderDict decompresses standard zlib streams without a dictionary when nil dict is provided
	{
		payload := []byte("Standard zlib stream without preset dictionary.")

		var buf bytes.Buffer
		w := zlib.NewWriter(&buf)
		if _, err := w.Write(payload); err != nil {
			fmt.Fprintf(os.Stderr, "assertion 3 setup failed: Write: %v\n", err)
			os.Exit(1)
		}
		if err := w.Close(); err != nil {
			fmt.Fprintf(os.Stderr, "assertion 3 setup failed: Close: %v\n", err)
			os.Exit(1)
		}

		r, err := zlib.NewReaderDict(&buf, nil)
		if err != nil {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: NewReaderDict with nil dict returned error: %v\n", err)
			os.Exit(1)
		}

		decompressed, err := io.ReadAll(r)
		if err != nil {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: io.ReadAll returned error: %v\n", err)
			os.Exit(1)
		}
		if err := r.Close(); err != nil {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: r.Close returned error: %v\n", err)
			os.Exit(1)
		}

		if !bytes.Equal(decompressed, payload) {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: decompressed data mismatch\n")
			os.Exit(1)
		}
	}

	// Assertion 4: NewReaderDict returns ErrHeader when provided invalid zlib header bytes
	{
		invalidHeader := []byte{0x00, 0x00, 0x00, 0x00}
		_, err := zlib.NewReaderDict(bytes.NewReader(invalidHeader), nil)
		if !errors.Is(err, zlib.ErrHeader) {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: expected ErrHeader, got: %v\n", err)
			os.Exit(1)
		}
	}

	// Assertion 5: NewReaderDict returns an io.ReadCloser that implements the Resetter interface for reusing the decompressor
	{
		dict1 := []byte("dictionary-first-run-777")
		dict2 := []byte("dictionary-second-run-888")
		msg1 := []byte("Message number one for reuse test.")
		msg2 := []byte("Message number two for reuse test with different dictionary.")

		var buf1 bytes.Buffer
		w1, _ := zlib.NewWriterLevelDict(&buf1, zlib.DefaultCompression, dict1)
		w1.Write(msg1)
		w1.Close()

		var buf2 bytes.Buffer
		w2, _ := zlib.NewWriterLevelDict(&buf2, zlib.DefaultCompression, dict2)
		w2.Write(msg2)
		w2.Close()

		r, err := zlib.NewReaderDict(&buf1, dict1)
		if err != nil {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: initial NewReaderDict: %v\n", err)
			os.Exit(1)
		}

		resetter, ok := r.(zlib.Resetter)
		if !ok {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: returned reader does not implement zlib.Resetter\n")
			os.Exit(1)
		}

		out1, err := io.ReadAll(r)
		if err != nil || !bytes.Equal(out1, msg1) {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: reading first stream: %v\n", err)
			os.Exit(1)
		}

		if err := resetter.Reset(&buf2, dict2); err != nil {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: resetter.Reset: %v\n", err)
			os.Exit(1)
		}

		out2, err := io.ReadAll(r)
		if err != nil || !bytes.Equal(out2, msg2) {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: reading second stream after reset: %v\n", err)
			os.Exit(1)
		}

		if err := r.Close(); err != nil {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: r.Close: %v\n", err)
			os.Exit(1)
		}
	}

	fmt.Println("All contract assertions passed successfully.")
}

Ursprungs-Seeder

anonym