split

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package split implements reading and writing of hashsplit trees in a blob store. See github.com/bobg/hashsplit for more information.

Index

Constants

This section is empty.

Variables

View Source
var File_split_proto protoreflect.FileDescriptor

Functions

func Protect

func Protect(ctx context.Context, g bs.Getter, ref bs.Ref) ([]gc.ProtectPair, error)

Protect is a gc.ProtectFunc for use on split.Node refs.

Types

type Child

type Child struct {

	// Ref of child (node or blob).
	Ref []byte `protobuf:"bytes,1,opt,name=ref,proto3" json:"ref,omitempty"`
	// Offset of this child (duplicates Node.off).
	Offset uint64 `protobuf:"varint,2,opt,name=offset,proto3" json:"offset,omitempty"`
	// contains filtered or unexported fields
}

func (*Child) Descriptor deprecated

func (*Child) Descriptor() ([]byte, []int)

Deprecated: Use Child.ProtoReflect.Descriptor instead.

func (*Child) GetOffset

func (x *Child) GetOffset() uint64

func (*Child) GetRef

func (x *Child) GetRef() []byte

func (*Child) ProtoMessage

func (*Child) ProtoMessage()

func (*Child) ProtoReflect

func (x *Child) ProtoReflect() protoreflect.Message

func (*Child) Reset

func (x *Child) Reset()

func (*Child) String

func (x *Child) String() string

type Node

type Node struct {

	// Offsets and refs of other Nodes.
	Nodes []*Child `protobuf:"bytes,1,rep,name=nodes,proto3" json:"nodes,omitempty"`
	// Offsets and refs of leaf blobs.
	Leaves []*Child `protobuf:"bytes,2,rep,name=leaves,proto3" json:"leaves,omitempty"`
	// Offset in the input stream of the beginning of the bytes represented by this child.
	Offset uint64 `protobuf:"varint,3,opt,name=offset,proto3" json:"offset,omitempty"`
	// Number of bytes represented by this node.
	Size uint64 `protobuf:"varint,4,opt,name=size,proto3" json:"size,omitempty"`
	// contains filtered or unexported fields
}

Node is a node in a hashsplit tree created with split.Write.

func (*Node) Descriptor deprecated

func (*Node) Descriptor() ([]byte, []int)

Deprecated: Use Node.ProtoReflect.Descriptor instead.

func (*Node) GetLeaves

func (x *Node) GetLeaves() []*Child

func (*Node) GetNodes

func (x *Node) GetNodes() []*Child

func (*Node) GetOffset

func (x *Node) GetOffset() uint64

func (*Node) GetSize

func (x *Node) GetSize() uint64

func (*Node) ProtoMessage

func (*Node) ProtoMessage()

func (*Node) ProtoReflect

func (x *Node) ProtoReflect() protoreflect.Message

func (*Node) Reset

func (x *Node) Reset()

func (*Node) String

func (x *Node) String() string

type Option

type Option = func(*Writer)

Option is the type of an option passed to NewWriter.

func Bits

func Bits(n uint) Option

Bits is an option for NewWriter that changes the number of trailing zero bits in the rolling checksum used to identify chunk boundaries. A chunk boundary occurs on average once every 2^n bytes. (But the actual median chunk size is the logarithm, base (2^n-1)/(2^n), of 0.5.) The default value for n is 16, producing a chunk boundary every 65,536 bytes, and a median chunk size of 45,426 bytes.

func Fanout

func Fanout(n uint) Option

Fanout is an option for NewWriter that can change the fanout of the nodes in the tree produced. The value of n must be 1 or higher. The default is 8. In a nutshell, nodes in the hashsplit tree will tend to have around 2n children each, because each chunk's "level" is reduced by dividing it by n. For more information see https://pkg.go.dev/github.com/bobg/hashsplit#TreeBuilder.Add.

func MinSize

func MinSize(n int) Option

MinSize is an option for NewWriter that sets a lower bound on the size of a chunk. No chunk may be smaller than this, except for the final one in the input stream. The value must be 64 or higher. The default is 1024.

type Reader

type Reader struct {
	Ctx context.Context
	// contains filtered or unexported fields
}

Reader traverses the nodes of a hashsplit tree to produce the original (unsplit) input. It implements io.ReadSeeker. The given context object is stored in the Reader and used in subsequent calls to Read. This is an antipattern but acceptable when an object must adhere to a context-free stdlib interface (https://github.com/golang/go/wiki/CodeReviewComments#contexts). Callers may replace the context object during the lifetime of the Reader as needed.

func NewReader

func NewReader(ctx context.Context, g bs.Getter, ref bs.Ref) (*Reader, error)

NewReader produces a new Reader for the hashsplit tree stored in g and rooted at ref.

func (*Reader) Read

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

Read implements io.Reader.

func (*Reader) Seek

func (r *Reader) Seek(offset int64, whence int) (int64, error)

Seek implements io.Seeker.

func (*Reader) Size

func (r *Reader) Size() uint64

Size returns the number of (unsplit) input bytes represented by the full hashsplit tree.

type Writer

type Writer struct {
	Ctx  context.Context
	Root bs.Ref // populated by Close
	// contains filtered or unexported fields
}

Writer is an io.WriteCloser that splits its input with a hashsplit.Splitter, writing the chunks to a bs.Store as separate blobs. It additionally assembles those chunks into a tree with a hashsplit.TreeBuilder. The tree nodes are also written to the bs.Store as serialized Node objects. The bs.Ref of the tree root is available as Writer.Root after a call to Close. If no data was written before the Writer was closed, Root will be bs.Zero.

func NewWriter

func NewWriter(ctx context.Context, st bs.Store, opts ...Option) *Writer

NewWriter produces a new Writer writing to the given blob store. The given context object is stored in the Writer and used in subsequent calls to Write and Close. This is an antipattern but acceptable when an object must adhere to a context-free stdlib interface (https://github.com/golang/go/wiki/CodeReviewComments#contexts). Callers may replace the context object during the lifetime of the Writer as needed.

func (*Writer) Close

func (w *Writer) Close() error

Close implements io.Closer.

func (*Writer) Write

func (w *Writer) Write(inp []byte) (int, error)

Write implements io.Writer.

Jump to

Keyboard shortcuts

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