CodeSampleX

샘플

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. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다.

sha256:178513401122ca8df461325adc547f87f6b1a723257aad9a8440da0a5b372569

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

컨트랙트

  1. mmap.Open memory-maps a file for read-only access
  2. mmap.ReaderAt.Len reports the byte length of the underlying mapped file
  3. mmap.ReaderAt.At accesses individual bytes by index without copying
  4. mmap.ReaderAt.ReadAt reads byte slices at arbitrary offsets and returns io.EOF at end of file
  5. 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

소스 아티팩트 내려받기 (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 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.
csx.json
{"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"}
go.mod
module example.com/mmapsample

go 1.26.0

require golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa
go.sum
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=
mmapsample.go
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
}
spec.json
{
  "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"
  ]
}
test/contract.go
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")
}

오리진 시더

익명