Exemplo
github.com/klauspost/compress v1.20.0: gzip.NewWriter
Amostra verificada para golang github.com/klauspost/compress v1.20.0: gzip.NewWriter. O contrato rodou em go 1.26 · linux debian/x64 · docker e passou.
sha256:decd882f99d769757572198a92527e04a512035c10d997817f7ee1be3c7772ab
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 1
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
linux 24 · ubuntu · glibc 2.39 x64 go
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| 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 |
Caso
HOW- Objetivo
- verify gzip.NewWriter in pkg:golang/github.com/klauspost/compress@v1.20.0
- Símbolos
-
- gzip.NewWriter
- Criado
- 2026-09-03T00:27:04Z
Contrato
- gzip.NewWriter creates a new Writer writing to the underlying io.Writer
- Writer.Write compresses data into the gzip stream
- Writer.Flush flushes any pending compressed data to the underlying writer
- Writer.Close finalizes the gzip stream and writes the stream footer
- Writer.Reset discards state and prepares the Writer to output to another stream
- Compressed output from gzip.NewWriter decompresses back to the exact input data
Arquivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Código-fonte
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 gzip.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:
- gzip.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:7de77f4c95aceaf1eac2bb4877debb176b3c5ff447e302e8a7d248a560b9fbac","contract":["gzip.NewWriter creates a new Writer writing to the underlying io.Writer","Writer.Write compresses data into the gzip stream","Writer.Flush flushes any pending compressed data to the underlying writer","Writer.Close finalizes the gzip stream and writes the stream footer","Writer.Reset discards state and prepares the Writer to output to another stream","Compressed output from gzip.NewWriter decompresses back to the exact input data"],"goal":"verify gzip.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":["gzip.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":["gzip.NewWriter"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.25
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"
"os"
"github.com/klauspost/compress/gzip"
)
func main() {
var buf bytes.Buffer
w := gzip.NewWriter(&buf)
data := "Demonstrating gzip.NewWriter compression with klauspost/compress"
if _, err := w.Write([]byte(data)); err != nil {
fmt.Fprintf(os.Stderr, "write error: %v\n", err)
os.Exit(1)
}
if err := w.Close(); err != nil {
fmt.Fprintf(os.Stderr, "close error: %v\n", err)
os.Exit(1)
}
compressedBytes := buf.Bytes()
compressedSize := len(compressedBytes)
r, err := gzip.NewReader(bytes.NewReader(compressedBytes))
if err != nil {
fmt.Fprintf(os.Stderr, "reader error: %v\n", err)
os.Exit(1)
}
defer r.Close()
decompressed, err := io.ReadAll(r)
if err != nil {
fmt.Fprintf(os.Stderr, "read error: %v\n", err)
os.Exit(1)
}
fmt.Printf("Original size: %d, compressed size: %d\n", len(data), compressedSize)
fmt.Printf("Decompressed string: %s\n", string(decompressed))
}
{
"schemaVersion": 1,
"goal": "verify gzip.NewWriter in pkg:golang/github.com/klauspost/compress@v1.20.0",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/klauspost/compress@v1.20.0"
],
"symbols": [
"gzip.NewWriter"
]
}
package main
import (
"bytes"
"fmt"
"io"
"os"
"github.com/klauspost/compress/gzip"
)
func main() {
// 1. gzip.NewWriter creates a new Writer writing to the underlying io.Writer
var buf1 bytes.Buffer
w1 := gzip.NewWriter(&buf1)
if w1 == nil {
fmt.Fprintf(os.Stderr, "expected non-nil gzip.Writer\n")
os.Exit(1)
}
// 2. Writer.Write compresses data into the gzip stream
part1 := []byte("Hello, ")
part2 := []byte("world! This is a test of klauspost/compress gzip.NewWriter.")
n1, err := w1.Write(part1)
if err != nil || n1 != len(part1) {
fmt.Fprintf(os.Stderr, "Write failed: err=%v, n=%d\n", err, n1)
os.Exit(1)
}
n2, err := w1.Write(part2)
if err != nil || n2 != len(part2) {
fmt.Fprintf(os.Stderr, "Write failed: err=%v, n=%d\n", err, n2)
os.Exit(1)
}
// 3. Writer.Flush flushes any pending compressed data to the underlying writer
if err := w1.Flush(); err != nil {
fmt.Fprintf(os.Stderr, "Flush failed: %v\n", err)
os.Exit(1)
}
if buf1.Len() == 0 {
fmt.Fprintf(os.Stderr, "expected flushed bytes in buffer, got 0\n")
os.Exit(1)
}
// 4. Writer.Close finalizes the gzip stream and writes the stream footer
lenBeforeClose := buf1.Len()
if err := w1.Close(); err != nil {
fmt.Fprintf(os.Stderr, "Close failed: %v\n", err)
os.Exit(1)
}
if buf1.Len() <= lenBeforeClose {
fmt.Fprintf(os.Stderr, "expected footer written on Close\n")
os.Exit(1)
}
// 5. Writer.Reset discards state and prepares the Writer to output to another stream
var buf2 bytes.Buffer
w1.Reset(&buf2)
resetData := []byte("Second stream using reset writer")
if _, err := w1.Write(resetData); err != nil {
fmt.Fprintf(os.Stderr, "Write after Reset failed: %v\n", err)
os.Exit(1)
}
if err := w1.Close(); err != nil {
fmt.Fprintf(os.Stderr, "Close after Reset failed: %v\n", err)
os.Exit(1)
}
rReset, err := gzip.NewReader(&buf2)
if err != nil {
fmt.Fprintf(os.Stderr, "NewReader for reset stream failed: %v\n", err)
os.Exit(1)
}
decompReset, err := io.ReadAll(rReset)
_ = rReset.Close()
if err != nil || !bytes.Equal(decompReset, resetData) {
fmt.Fprintf(os.Stderr, "Reset verification failed: %s != %s\n", decompReset, resetData)
os.Exit(1)
}
// 6. Compressed output from gzip.NewWriter decompresses back to the exact input data
r1, err := gzip.NewReader(&buf1)
if err != nil {
fmt.Fprintf(os.Stderr, "NewReader failed: %v\n", err)
os.Exit(1)
}
decomp1, err := io.ReadAll(r1)
_ = r1.Close()
if err != nil {
fmt.Fprintf(os.Stderr, "ReadAll failed: %v\n", err)
os.Exit(1)
}
expected1 := append(part1, part2...)
if !bytes.Equal(decomp1, expected1) {
fmt.Fprintf(os.Stderr, "decompressed data mismatch: got %q, expected %q\n", decomp1, expected1)
os.Exit(1)
}
fmt.Println("All gzip.NewWriter contract assertions passed.")
}
Seeder de origem
anônimo