示例
golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa: mmap.Open, mmap.ReaderAt
已验证示例 — golang golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa: mmap.Open, mmap.ReaderAt. contract 在 go 1.26 · linux debian/x64 · docker 上运行并通过.
sha256:178513401122ca8df461325adc547f87f6b1a723257aad9a8440da0a5b372569
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 go 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-03 |
案例
HOW- 目标
- verify pkg:golang/golang.org/x/exp@v0.0.0-20260824195058-e88cd73687aa
- 符号
-
- golang.org/x/exp/mmap.Open
- golang.org/x/exp/mmap.ReaderAt
- 创建时间
- 2026-09-03T23:27:27Z
契约
- mmap.Open memory-maps a file for read-only access
- mmap.ReaderAt.Len reports the byte length of the underlying mapped file
- mmap.ReaderAt.At accesses individual bytes by index without copying
- mmap.ReaderAt.ReadAt reads byte slices at arbitrary offsets and returns io.EOF at end of file
- mmap.ReaderAt.Close unmaps the memory region and causes subsequent reads to fail
文件
- PROMPT.md
- csx.json
- go.mod
- go.sum
- mmapsample.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 pkg:golang/golang.org/x/exp@v0.0.0-20260824195058-e88cd73687aa
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/exp@v0.0.0-20260824195058-e88cd73687aa
Demonstrate these symbols/APIs:
- golang.org/x/exp/mmap.Open
- golang.org/x/exp/mmap.ReaderAt
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:df25901db88884777e25bae6186bd512791ff02b3edef3bc86eb6dc175e0a390","contract":["mmap.Open memory-maps a file for read-only access","mmap.ReaderAt.Len reports the byte length of the underlying mapped file","mmap.ReaderAt.At accesses individual bytes by index without copying","mmap.ReaderAt.ReadAt reads byte slices at arbitrary offsets and returns io.EOF at end of file","mmap.ReaderAt.Close unmaps the memory region and causes subsequent reads to fail"],"goal":"verify pkg:golang/golang.org/x/exp@v0.0.0-20260824195058-e88cd73687aa","kind":"HOW","packages":["pkg:golang/golang.org/x/exp@v0.0.0-20260824195058-e88cd73687aa"],"schemaVersion":1,"symbols":["golang.org/x/exp/mmap.Open","golang.org/x/exp/mmap.ReaderAt"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/exp@v0.0.0-20260824195058-e88cd73687aa"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/exp@v0.0.0-20260824195058-e88cd73687aa","symbols":["golang.org/x/exp/mmap.Open","golang.org/x/exp/mmap.ReaderAt"],"verifierAdapter":"golang@1"}
module example.com/mmapsample
go 1.26.0
require golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa
golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa h1:QSyA8ishJCyT21kER9KwNt0b7BM3iRK4x9QXhjN5Fdk=
golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa/go.mod h1:zeBbvyFKDaLwa7CH/zI8KXt7gTl14SF7sO08Pl5jBCM=
package mmapsample
import (
"golang.org/x/exp/mmap"
)
// OpenFile opens and memory-maps the named file for reading.
func OpenFile(filename string) (*mmap.ReaderAt, error) {
return mmap.Open(filename)
}
// ReadChunk reads a byte chunk of the given length at offset from the memory-mapped reader.
func ReadChunk(r *mmap.ReaderAt, offset int64, length int) ([]byte, error) {
buf := make([]byte, length)
n, err := r.ReadAt(buf, offset)
return buf[:n], err
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/golang.org/x/exp@v0.0.0-20260824195058-e88cd73687aa",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/exp@v0.0.0-20260824195058-e88cd73687aa"
],
"symbols": [
"golang.org/x/exp/mmap.Open",
"golang.org/x/exp/mmap.ReaderAt"
]
}
package main
import (
"bytes"
"fmt"
"io"
"os"
"path/filepath"
"example.com/mmapsample"
"golang.org/x/exp/mmap"
)
func main() {
tmpDir, err := os.MkdirTemp("", "mmap-contract-*")
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: failed to create temp dir: %v\n", err)
os.Exit(1)
}
defer os.RemoveAll(tmpDir)
filePath := filepath.Join(tmpDir, "sample.txt")
testData := []byte("The quick brown fox jumps over the lazy dog. CodeSampleX mmap verification!")
if err := os.WriteFile(filePath, testData, 0600); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: failed to write test file: %v\n", err)
os.Exit(1)
}
// 1. mmap.Open memory-maps a file for read-only access
var reader *mmap.ReaderAt
reader, err = mmap.Open(filePath)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: mmap.Open failed: %v\n", err)
os.Exit(1)
}
defer reader.Close()
// 2. mmap.ReaderAt.Len reports the byte length of the underlying mapped file
if reader.Len() != len(testData) {
fmt.Fprintf(os.Stderr, "FAIL: ReaderAt.Len() = %d, want %d\n", reader.Len(), len(testData))
os.Exit(1)
}
// 3. mmap.ReaderAt.At accesses individual bytes by index without copying
if reader.At(0) != 'T' || reader.At(4) != 'q' || reader.At(len(testData)-1) != '!' {
fmt.Fprintf(os.Stderr, "FAIL: ReaderAt.At returned unexpected bytes\n")
os.Exit(1)
}
// 4. mmap.ReaderAt.ReadAt reads byte slices at arbitrary offsets and returns io.EOF at end of file
midBuf, err := mmapsample.ReadChunk(reader, 10, 5) // "brown"
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: ReadChunk mid failed: %v\n", err)
os.Exit(1)
}
if string(midBuf) != "brown" {
fmt.Fprintf(os.Stderr, "FAIL: ReadChunk mid mismatch: got %q, want %q\n", string(midBuf), "brown")
os.Exit(1)
}
endBuf := make([]byte, 30)
offset := int64(len(testData) - 13) // "verification!"
n, err := reader.ReadAt(endBuf, offset)
if err != io.EOF {
fmt.Fprintf(os.Stderr, "FAIL: ReadAt at end expected io.EOF, got %v\n", err)
os.Exit(1)
}
if n != 13 || !bytes.Equal(endBuf[:n], []byte("verification!")) {
fmt.Fprintf(os.Stderr, "FAIL: ReadAt at end mismatch: got %q (len %d), want %q\n", string(endBuf[:n]), n, "verification!")
os.Exit(1)
}
// 5. mmap.ReaderAt.Close unmaps the memory region and causes subsequent reads to fail
if err := reader.Close(); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: ReaderAt.Close failed: %v\n", err)
os.Exit(1)
}
buf := make([]byte, 5)
_, err = reader.ReadAt(buf, 0)
if err == nil {
fmt.Fprintf(os.Stderr, "FAIL: ReadAt succeeded after Close\n")
os.Exit(1)
}
// Idempotent close
if err := reader.Close(); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: second Close returned error: %v\n", err)
os.Exit(1)
}
fmt.Println("PASS: golang.org/x/exp/mmap contract verified")
}
原始种子者
匿名