mmap

package
v0.2.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: BSD-2-Clause, BSD-3-Clause Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mmap provides a way to memory-map a file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader struct {
	*ReaderAt
	// contains filtered or unexported fields
}

func NewReader

func NewReader(readerAt *ReaderAt) *Reader

func (*Reader) Read

func (r *Reader) Read(buf []byte) (n int, err error)

Read implements io.Reader. The end of the mapped content is reported as io.EOF, never as a zero-length read with a nil error, so a caller that reads until EOF cannot spin.

type ReaderAt

type ReaderAt struct {
	// contains filtered or unexported fields
}

ReaderAt reads a memory-mapped file.

Like any io.ReaderAt, clients can execute parallel ReadAt calls, but it is not safe to call Close and reading methods concurrently.

func Open

func Open(filename string) (*ReaderAt, error)

Open opens the named file with one metadata read. Close releases its mapping and descriptor.

func OpenWithInfo added in v0.2.3

func OpenWithInfo(filename string, info os.FileInfo) (*ReaderAt, error)

OpenWithInfo opens the named file using metadata already collected by the caller. The caller keeps the file stable while it is read. A nil info obtains metadata from the opened descriptor.

func (*ReaderAt) At

func (r *ReaderAt) At(i int) byte

At returns the byte at index i.

func (*ReaderAt) Close

func (r *ReaderAt) Close() error

Close releases the mapping and then the descriptor it was created from. It is idempotent: a second call releases nothing, and an empty mapping still closes the descriptor it retains.

func (*ReaderAt) File added in v0.2.1

func (r *ReaderAt) File() *os.File

File returns the descriptor the mapping was created from, or nil once the reader is closed. The reader owns that descriptor for its whole lifecycle: Close removes the mapping and then closes it, so a caller that still needs the descriptor keeps the reader open until it is done. It must also keep the reader reachable, because the finalizer closes the descriptor once the reader is unreachable, and holding only the returned *os.File does not keep the reader alive.

func (*ReaderAt) Len

func (r *ReaderAt) Len() int

Len returns the length of the underlying memory-mapped file.

func (*ReaderAt) ReadAt

func (r *ReaderAt) ReadAt(p []byte, off int64) (int, error)

ReadAt implements the io.ReaderAt interface.

func (*ReaderAt) Slice

func (r *ReaderAt) Slice(off, limit int64) ([]byte, error)

ReadAt implements the io.ReaderAt interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL