CodeSampleX

샘플

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

검증된 샘플 — golang github.com/klauspost/compress v1.19.1: zlib.NewReaderDict. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다.

sha256:1326ef7c20d3b23ec164dfb0c3faf525dc5a866a4233f1ade67a69163d387404

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 go 1.26 linux 24 · ubuntu · glibc 2.39 amd64 go 1.26 go 1.26 go 1

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify github.com/klauspost/compress/zlib.NewReaderDict in pkg:golang/github.com/klauspost/compress@v1.19.1
패키지
심벌
  • github.com/klauspost/compress/zlib.NewReaderDict
환경
go 1.26.6
생성일
2026-10-11T06:58:16Z

컨트랙트

  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

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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

오리진 시더

익명