mmap

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: MIT Imports: 7 Imported by: 0

README

mmap for Human

Go Reference Test Status codecov

An easy to use mmap wrapper for go. Support read, write and auto grow.

Installation

go get -u github.com/ImSingee/mmap

Quick Start

package main

import "github.com/ImSingee/mmap"

func main() {
	f, err := mmap.New(mmap.NewReadWrite(""))
	if err != nil {
		panic("Cannot init mmap: " + err.Error())
	}
	defer f.Close()

	_, err = f.WriteAt([]byte("Hello World!"), 0)
	if err != nil {
		panic(err)
	}
}

License

MIT License

Documentation

Index

Constants

View Source
const DefaultInitLength = oneMB

Variables

View Source
var ErrIsClosed = fmt.Errorf("mmap is closed")
View Source
var ErrOverflow = fmt.Errorf("mmap access out of bound")

Functions

func DefaultGrowPolicy

func DefaultGrowPolicy(current int, atLeast int) (next int)

Types

type Args

type Args struct {
	File       string
	InitLength int
	Readonly   bool
	Private    bool
}

func NewReadOnly

func NewReadOnly(file string) *Args

func NewReadWrite

func NewReadWrite(file string) *Args

func (*Args) Clean

func (a *Args) Clean() error

func (*Args) Flags

func (a *Args) Flags() int

func (*Args) InitialSize

func (a *Args) InitialSize() int

func (*Args) Offset

func (a *Args) Offset() int64

func (*Args) Open

func (a *Args) Open() (*os.File, error)

func (*Args) Prot

func (a *Args) Prot() int

type Grower

type Grower func(current int, atLeast int) (next int)

type Mmap

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

func New

func New(args Opener) (*Mmap, error)

func (*Mmap) Bytes

func (m *Mmap) Bytes(offset int64, length int) ([]byte, error)

func (*Mmap) Cap

func (m *Mmap) Cap() int

func (*Mmap) ChangeGrowPolicy

func (m *Mmap) ChangeGrowPolicy(newGrowPolicy Grower)

func (*Mmap) Close

func (m *Mmap) Close() error

func (*Mmap) Copy added in v1.2.0

func (m *Mmap) Copy(srcPos, dstPos int64, length int) error

func (*Mmap) EnsureCapacity

func (m *Mmap) EnsureCapacity(size int) error

func (*Mmap) IsClosed

func (m *Mmap) IsClosed() bool

func (*Mmap) ReadAt

func (m *Mmap) ReadAt(p []byte, off int64) (n int, err error)

func (*Mmap) ReaderAt added in v1.3.0

func (m *Mmap) ReaderAt(off int64) Reader

func (*Mmap) WriteAt

func (m *Mmap) WriteAt(p []byte, off int64) (n int, err error)

func (*Mmap) WriteTo

func (m *Mmap) WriteTo(w io.Writer) (n int64, err error)

func (*Mmap) WriteToAt added in v1.1.0

func (m *Mmap) WriteToAt(offset int64, w io.Writer) (n int64, err error)

func (*Mmap) WriterAt added in v1.3.0

func (m *Mmap) WriterAt(off int64) Writer

type Opener

type Opener interface {
	Open() (*os.File, error)
	Offset() int64
	InitialSize() int
	Prot() int
	Flags() int
}

type Reader added in v1.3.0

type Reader interface {
	io.Reader
}

type Writer added in v1.3.0

type Writer interface {
	io.Writer
	io.StringWriter
}

Jump to

Keyboard shortcuts

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