Ejemplo
github.com/klauspost/compress v1.20.0: snappy.NewWriter
Muestra verificada para golang github.com/klauspost/compress v1.20.0: snappy.NewWriter. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y pasó.
sha256:906b116b6715b2ed6624afe25459a4d42d93347893c1259e94f66d90ad2c06a6
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
linux 24 · ubuntu · glibc 2.39 x64 go
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| 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 snappy.NewWriter in pkg:golang/github.com/klauspost/compress@v1.20.0
- Símbolos
-
- snappy.NewWriter
- Creado
- 2026-09-03T00:33:55Z
Contrato
- snappy.NewWriter returns a non-nil *snappy.Writer wrapping the target io.Writer
- snappy.Writer compresses data written through Write method into Snappy framing stream
- snappy.Writer.Close flushes and finalizes the compressed stream
- snappy.Writer.Reset redirects subsequent compressed writes to a new io.Writer
- decompression with snappy.NewReader recovers the exact original bytes written by snappy.NewWriter
Archivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Código fuente
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 snappy.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:
- snappy.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:70a636d0e648acb736f7d38ad504f87242fb0c58045f0c22306ee5269c32c93b","contract":["snappy.NewWriter returns a non-nil *snappy.Writer wrapping the target io.Writer","snappy.Writer compresses data written through Write method into Snappy framing stream","snappy.Writer.Close flushes and finalizes the compressed stream","snappy.Writer.Reset redirects subsequent compressed writes to a new io.Writer","decompression with snappy.NewReader recovers the exact original bytes written by snappy.NewWriter"],"goal":"verify snappy.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":["snappy.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":["snappy.NewWriter"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.6
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"
"github.com/klauspost/compress/snappy"
)
func main() {
var buf bytes.Buffer
w := snappy.NewWriter(&buf)
data := []byte("Streaming compression with klauspost/compress snappy.NewWriter")
if _, err := w.Write(data); err != nil {
panic(err)
}
if err := w.Close(); err != nil {
panic(err)
}
compressedLen := buf.Len()
r := snappy.NewReader(&buf)
decompressed, err := io.ReadAll(r)
if err != nil {
panic(err)
}
fmt.Printf("Compressed %d bytes down to %d bytes\n", len(data), compressedLen)
fmt.Printf("Decompressed string: %s\n", string(decompressed))
}
{
"schemaVersion": 1,
"goal": "verify snappy.NewWriter in pkg:golang/github.com/klauspost/compress@v1.20.0",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/klauspost/compress@v1.20.0"
],
"symbols": [
"snappy.NewWriter"
]
}
package main
import (
"bytes"
"fmt"
"io"
"os"
"github.com/klauspost/compress/snappy"
)
func main() {
// 1. snappy.NewWriter returns a non-nil *snappy.Writer wrapping the target io.Writer
var buf bytes.Buffer
w := snappy.NewWriter(&buf)
if w == nil {
fmt.Fprintln(os.Stderr, "FAIL: snappy.NewWriter returned nil")
os.Exit(1)
}
// 2. snappy.Writer compresses data written through Write method into Snappy framing stream
input1 := []byte("CodeSampleX contract verification: snappy.Writer streaming compression.")
n, err := w.Write(input1)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: w.Write failed: %v\n", err)
os.Exit(1)
}
if n != len(input1) {
fmt.Fprintf(os.Stderr, "FAIL: w.Write short write: got %d want %d\n", n, len(input1))
os.Exit(1)
}
// 3. snappy.Writer.Close flushes and finalizes the compressed stream
if err := w.Close(); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: w.Close failed: %v\n", err)
os.Exit(1)
}
compressed1 := buf.Bytes()
if len(compressed1) == 0 {
fmt.Fprintln(os.Stderr, "FAIL: compressed stream is empty after Close")
os.Exit(1)
}
snappyMagic := []byte("\xff\x06\x00\x00sNaPpY")
if !bytes.HasPrefix(compressed1, snappyMagic) {
fmt.Fprintf(os.Stderr, "FAIL: compressed stream missing Snappy magic header\n")
os.Exit(1)
}
// 4. snappy.Writer.Reset redirects subsequent compressed writes to a new io.Writer
var buf2 bytes.Buffer
w.Reset(&buf2)
input2 := []byte("Second stream payload following snappy.Writer.Reset call.")
n2, err := w.Write(input2)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: w.Write after Reset failed: %v\n", err)
os.Exit(1)
}
if n2 != len(input2) {
fmt.Fprintf(os.Stderr, "FAIL: w.Write after Reset short write: got %d want %d\n", n2, len(input2))
os.Exit(1)
}
if err := w.Close(); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: w.Close after Reset failed: %v\n", err)
os.Exit(1)
}
compressed2 := buf2.Bytes()
if !bytes.HasPrefix(compressed2, snappyMagic) {
fmt.Fprintf(os.Stderr, "FAIL: second stream missing Snappy magic header\n")
os.Exit(1)
}
// 5. decompression with snappy.NewReader recovers the exact original bytes written by snappy.NewWriter
r1 := snappy.NewReader(bytes.NewReader(compressed1))
decomp1, err := io.ReadAll(r1)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: ReadAll on stream 1 failed: %v\n", err)
os.Exit(1)
}
if !bytes.Equal(decomp1, input1) {
fmt.Fprintf(os.Stderr, "FAIL: stream 1 mismatch: got %q want %q\n", decomp1, input1)
os.Exit(1)
}
r2 := snappy.NewReader(bytes.NewReader(compressed2))
decomp2, err := io.ReadAll(r2)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: ReadAll on stream 2 failed: %v\n", err)
os.Exit(1)
}
if !bytes.Equal(decomp2, input2) {
fmt.Fprintf(os.Stderr, "FAIL: stream 2 mismatch: got %q want %q\n", decomp2, input2)
os.Exit(1)
}
fmt.Println("All contract assertions passed successfully.")
}
Seeder de origen
anónimo