blob

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 5 Imported by: 4

Documentation

Overview

Package blob defines a common data interchange type for keyvalue FS's.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Grow

func Grow(b Blob, offset int64) error

Grow attempts to call an optimized blob.Grow(), falls back to copying into Bytes and running Bytes.Grow().

func Set

func Set(dest Blob, src Blob, offset int64) (n int, err error)

Set attempts to call an optimized blob.Set(), falls back to copying into Bytes and running Bytes.Set().

func Truncate

func Truncate(b Blob, size int64) error

Truncate attempts to call an optimized blob.Truncate(), falls back to copying into Bytes and running Bytes.Truncate().

func Write

func Write(dest io.Writer, src Blob) (n int, err error)

Write writes 'src' into 'dest'. Attempts to use an optimized WriteBlob if available.

func WriteAt

func WriteAt(dest io.WriterAt, src Blob, destOffset int64) (n int, err error)

WriteAt writes 'src' into 'dest' starting at 'destOffset'. Attempts to use an optimized WriteBlobAt if available.

Types

type Blob

type Blob interface {
	// Bytes returns the byte slice equivalent to the data in this Blob.
	Bytes() []byte
	// Len returns the number of bytes contained in this blob.
	// Can be used to avoid unnecessary conversions and allocations from len(Bytes()).
	Len() int
}

Blob is a binary blob of data that can support platform-optimized mutations for better performance.

func Read

func Read(src io.Reader, length int) (blob Blob, n int, err error)

Read reads 'src' into a new Blob up to length bytes. Attempts to use an optimized ReadBlob if available.

func ReadAt

func ReadAt(src io.ReaderAt, length int, srcOffset int64) (blob Blob, n int, err error)

ReadAt reads 'src' into a new Blob up to length bytes starting at 'srcOffset'. Attempts to use an optimized ReadBlobAt if available.

func Slice

func Slice(b Blob, start, end int64) (Blob, error)

Slice attempts to call an optimized blob.Slice(), falls back to copying into Bytes and running Bytes.Slice().

func View

func View(b Blob, start, end int64) (Blob, error)

View attempts to call an optimized blob.View(), falls back to copying into Bytes and running Bytes.View().

type Bytes

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

Bytes is a Blob that wraps a byte slice.

func NewBytes

func NewBytes(buf []byte) *Bytes

NewBytes returns a Blob that wraps the given byte slice. Mutations to this Blob are reflected in the original slice.

func NewBytesLength

func NewBytesLength(length int) *Bytes

NewBytesLength returns a new Bytes with the given length of zero-byte data.

func (*Bytes) Bytes

func (b *Bytes) Bytes() []byte

Bytes implements Blob.

func (*Bytes) Grow

func (b *Bytes) Grow(offset int64) error

Grow implements Blob.

func (*Bytes) Len

func (b *Bytes) Len() int

Len implements Blob.

func (*Bytes) Set

func (b *Bytes) Set(src Blob, destStart int64) (n int, err error)

Set implements Blob.

func (*Bytes) Slice

func (b *Bytes) Slice(start, end int64) (Blob, error)

Slice implements Blob.

func (*Bytes) Truncate

func (b *Bytes) Truncate(size int64) error

Truncate implements Blob.

func (*Bytes) View

func (b *Bytes) View(start, end int64) (Blob, error)

View implements Blob.

type GrowBlob

type GrowBlob interface {
	Blob
	Grow(offset int64) error
}

GrowBlob is a Blob that can increase it's size by allocating offset bytes at the end.

type Reader

type Reader interface {
	ReadBlob(length int) (blob Blob, n int, err error)
}

Reader reads a Blob of up to 'length' bytes.

type ReaderAt

type ReaderAt interface {
	ReadBlobAt(length int, srcOffset int64) (blob Blob, n int, err error)
}

ReaderAt reads a Blob of up to 'length' bytes starting from this reader's 'srcOffset'.

type SetBlob

type SetBlob interface {
	Blob
	Set(src Blob, offset int64) (n int, err error)
}

SetBlob is a Blob that can copy 'src' into itself starting at the given offset into this Blob. Use View() on 'src' to control the maximum that is copied into this Blob.

type SliceBlob

type SliceBlob interface {
	Blob
	Slice(start, end int64) (Blob, error)
}

SliceBlob is a Blob that can return a copy of the data between start and end.

type TruncateBlob

type TruncateBlob interface {
	Blob
	Truncate(size int64) error
}

TruncateBlob is a Blob that can cut off bytes from the end until it is 'size' bytes long.

type ViewBlob

type ViewBlob interface {
	Blob
	View(start, end int64) (Blob, error)
}

ViewBlob is a Blob that can return a view into the same underlying data. Mutating the returned Blob also mutates the original.

type Writer

type Writer interface {
	WriteBlob(src Blob) (n int, err error)
}

Writer writes 'src' to this writer.

type WriterAt

type WriterAt interface {
	WriteBlobAt(src Blob, destOffset int64) (n int, err error)
}

WriterAt writes 'src' to this writer starting at 'destOffset'.

Jump to

Keyboard shortcuts

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