transaction

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package transaction provides the transaction on the raw byte data.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = fmt.Errorf("transaction: transaction closed")

ErrClosed is the error which returns when tries to access the closed transaction.

View Source
var ErrUnavailable = fmt.Errorf("transaction: data not available")

ErrUnavailable is the error which returns when tries to accessing the data which is not available.

Functions

This section is empty.

Types

type Tx

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

Tx is a transaction on the raw byte data.

func Begin

func Begin(data []byte, offset int64, length uintptr) (*Tx, error)

Begin starts and returns a new transaction. The given raw byte data starting from the given offset and ends after the given length copies to the snapshot which is allocated into the heap.

func (*Tx) Commit

func (tx *Tx) Commit() error

Commit flushes the snapshot to the original, closes this transaction and frees all resources associated with it. Note that it doesn't check that the original is still available for writing.

func (*Tx) Length

func (tx *Tx) Length() uintptr

Length returns the length, in bytes, of the data which is available for this transaction.

func (*Tx) Offset

func (tx *Tx) Offset() int64

Offset returns the lowest offset from start of the original which is available for this transaction.

func (*Tx) ReadAt

func (tx *Tx) ReadAt(buf []byte, offset int64) (int, error)

ReadAt reads len(buf) bytes at given offset from start of the original from the snapshot. If the given offset is outside of the accessible range the ErrUnavailable error will be returned. If there are not enough bytes to read then will be read how many there is and the number of read bytes will be returned with the ErrUnavailable error. Otherwise len(buf) will be returned with no errors. ReadAt implements the io.ReaderAt interface.

func (*Tx) Rollback

func (tx *Tx) Rollback() error

Rollback closes this transaction and frees all resources associated with it.

func (*Tx) WriteAt

func (tx *Tx) WriteAt(buf []byte, offset int64) (int, error)

WriteAt writes len(buf) bytes at given offset from start of the original into the snapshot. If the given offset is outside of the accessible range the ErrUnavailable error will be returned. If there are not enough space to write all given bytes then will be written as much as possible and the number of written bytes will be returned with the ErrUnavailable error. Otherwise len(buf) will be returned with no errors. WriteAt implements the io.WriterAt interface.

Jump to

Keyboard shortcuts

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