Пример
github.com/klauspost/compress v1.19.1: zlib.NewWriter
Проверенный пример — golang github.com/klauspost/compress v1.19.1: zlib.NewWriter. Контракт выполнен на go 1.26 · linux debian/x64 · docker и пройден.
sha256:ddaec8b898032d5c2eb640f1f70a8bb2b1691f517fea833b0837d1e7ffca6307
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
linux 24 · ubuntu · glibc 2.39 x64 go
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| 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 |
Кейс
HOW- Цель
- verify github.com/klauspost/compress/zlib.NewWriter in pkg:golang/github.com/klauspost/compress@v1.19.1
- Символы
-
- github.com/klauspost/compress/zlib.NewWriter
- Создан
- 2026-09-10T22:29:09Z
Контракт
- 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
Файлы
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Исходный код
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.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.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:4e172e4e722773fea0cb0d2481805b992d294107859aafaa0ef3cb4935c9b8f2","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.19.1","kind":"HOW","packages":["pkg:golang/github.com/klauspost/compress@v1.19.1"],"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.19.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/klauspost/compress@v1.19.1","symbols":["github.com/klauspost/compress/zlib.NewWriter"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.6
require github.com/klauspost/compress v1.19.1 // indirect
github.com/klauspost/compress v1.19.1 h1:VsB4HPswih7mmZ8WleSFQ75c/Ui1M4trX5oAsJnhSlk=
github.com/klauspost/compress v1.19.1/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
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.19.1",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/klauspost/compress@v1.19.1"
],
"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.")
}
Исходный сидер
аноним