Documentation
¶
Index ¶
- func CommitWriter(w *Writer) (*block.BlockRef, *block.Cursor, error)
- func FetchToBuffer(ctx context.Context, bcs *block.Cursor, buf *bytes.Buffer) error
- func FetchToBytes(ctx context.Context, bcs *block.Cursor) ([]byte, error)
- func NewFileBlock() block.Block
- func NewRangeSet(v *[]*Range, bcs *block.Cursor) *sbset.SubBlockSet
- type File
- func BuildFileWithBytes(ctx context.Context, bcs *block.Cursor, data []byte, ...) (*File, error)
- func BuildFileWithReader(ctx context.Context, bcs *block.Cursor, rdr io.Reader, ...) (*File, error)
- func NewFileWithBlob(rootBlob *blob.Blob) *File
- func UnmarshalFile(ctx context.Context, bcs *block.Cursor) (*File, error)
- func (f *File) ApplySubBlock(id uint32, next block.SubBlock) error
- func (f *File) BlockAliasIdentity() *block.AliasIdentityToken
- func (m *File) CloneMessageVT() protobuf_go_lite.CloneMessage
- func (m *File) CloneVT() *File
- func (this *File) EqualMessageVT(thatMsg any) bool
- func (this *File) EqualVT(that *File) bool
- func (x *File) GetRangeNonce() uint64
- func (x *File) GetRanges() []*Range
- func (x *File) GetRootBlob() *blob.Blob
- func (f *File) GetSubBlockCtor(id uint32) block.SubBlockCtor
- func (f *File) GetSubBlocks() map[uint32]block.SubBlock
- func (x *File) GetTotalSize() uint64
- func (f *File) IsNil() bool
- func (f *File) MarshalBlock() ([]byte, error)
- func (x *File) MarshalJSON() ([]byte, error)
- func (x *File) MarshalProtoJSON(s *json.MarshalState)
- func (x *File) MarshalProtoText() string
- func (m *File) MarshalToSizedBufferVT(dAtA []byte) (int, error)
- func (m *File) MarshalToVT(dAtA []byte) (int, error)
- func (m *File) MarshalVT() (dAtA []byte, err error)
- func (*File) ProtoMessage()
- func (x *File) Reset()
- func (m *File) SizeVT() (n int)
- func (x *File) String() string
- func (f *File) UnmarshalBlock(data []byte) error
- func (x *File) UnmarshalJSON(b []byte) error
- func (x *File) UnmarshalProtoJSON(s *json.UnmarshalState)
- func (m *File) UnmarshalVT(dAtA []byte) error
- func (f *File) Validate() error
- type Handle
- func (r *Handle) Close() error
- func (r *Handle) ComputeStorageSize(ctx context.Context) (uint64, error)
- func (r *Handle) GetCursor() *block.Cursor
- func (r *Handle) GetRef() *block.BlockRef
- func (r *Handle) Read(p []byte) (n int, err error)
- func (r *Handle) Seek(offset int64, whence int) (int64, error)
- func (r *Handle) Size() uint64
- type HandleRangeSlice
- type Range
- func (r *Range) ApplyBlockRef(id uint32, ptr *block.BlockRef) error
- func (r *Range) BlockAliasIdentity() *block.AliasIdentityToken
- func (m *Range) CloneMessageVT() protobuf_go_lite.CloneMessage
- func (m *Range) CloneVT() *Range
- func (this *Range) EqualMessageVT(thatMsg any) bool
- func (this *Range) EqualVT(that *Range) bool
- func (r *Range) FollowBlob(bcs *block.Cursor) *block.Cursor
- func (r *Range) GetBlockRefCtor(id uint32) block.Ctor
- func (r *Range) GetBlockRefs() (map[uint32]*block.BlockRef, error)
- func (x *Range) GetLength() uint64
- func (x *Range) GetNonce() uint64
- func (x *Range) GetRef() *block.BlockRef
- func (x *Range) GetStart() uint64
- func (r *Range) IsNil() bool
- func (r *Range) LessThanRange(other *Range) bool
- func (x *Range) MarshalJSON() ([]byte, error)
- func (x *Range) MarshalProtoJSON(s *json.MarshalState)
- func (x *Range) MarshalProtoText() string
- func (m *Range) MarshalToSizedBufferVT(dAtA []byte) (int, error)
- func (m *Range) MarshalToVT(dAtA []byte) (int, error)
- func (m *Range) MarshalVT() (dAtA []byte, err error)
- func (*Range) ProtoMessage()
- func (x *Range) Reset()
- func (m *Range) SizeVT() (n int)
- func (x *Range) String() string
- func (x *Range) UnmarshalJSON(b []byte) error
- func (x *Range) UnmarshalProtoJSON(s *json.UnmarshalState)
- func (m *Range) UnmarshalVT(dAtA []byte) error
- type RangeSlice
- type Writer
- func (w *Writer) Reset()
- func (w *Writer) Truncate(size uint64) error
- func (w *Writer) Write(p []byte) (n int, err error)
- func (w *Writer) WriteBlob(index, size uint64, ref *block.BlockRef) error
- func (w *Writer) WriteBytes(index uint64, data []byte) error
- func (w *Writer) WriteFrom(index uint64, dataLen int64, dataRdr io.Reader) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommitWriter ¶
CommitWriter commits any pending writes using a block transaction. Note: the block transaction must match the handle's block cursor.
func FetchToBuffer ¶
FetchToBuffer fetches a full File to a buffer.
func FetchToBytes ¶
FetchToBytes fetches to a bytes slice.
func NewRangeSet ¶
func NewRangeSet(v *[]*Range, bcs *block.Cursor) *sbset.SubBlockSet
NewRangeSet builds a new range set container.
bcs should be located at the range set sub-block.
Types ¶
type File ¶
type File struct {
// TotalSize is the total size of the file.
TotalSize uint64 `protobuf:"varint,1,opt,name=total_size,json=totalSize,proto3" json:"totalSize,omitempty"`
// RootBlob, if set, contains the entire file in a blob.
// Used when there is a single Range of data starting at index 0.
// If unset and len(ranges) == 0, the file is empty (all zeros).
RootBlob *blob.Blob `protobuf:"bytes,2,opt,name=root_blob,json=rootBlob,proto3" json:"rootBlob,omitempty"`
// RangeNonce is the next range nonce id to use.
RangeNonce uint64 `protobuf:"varint,3,opt,name=range_nonce,json=rangeNonce,proto3" json:"rangeNonce,omitempty"`
// Ranges contains file data ranges.
// Files are sparse when created.
// Ranges may overlap.
Ranges []*Range `protobuf:"bytes,4,rep,name=ranges,proto3" json:"ranges,omitempty"`
// contains filtered or unexported fields
}
File defines a pattern for storing a block-addressed file. Changes are transactional and deterministic. File write ranges and write mode are considered. Concurrent O_APPEND is implemented. Blobs are addressed as they are added, and periodically compacted. Some operations partially overwrite old blobs without rewriting them. The File object contains metadata and might contain links to sub-objects. Rabin fingerprinting is used to select deterministic chunk sizes.
func BuildFileWithBytes ¶
func BuildFileWithBytes( ctx context.Context, bcs *block.Cursor, data []byte, buildBlobOpts *blob.BuildBlobOpts, ) (*File, error)
BuildFileWithBytes builds a file with data, building the root blob. The new root will be stored at bcs.
func BuildFileWithReader ¶
func BuildFileWithReader( ctx context.Context, bcs *block.Cursor, rdr io.Reader, buildBlobOpts *blob.BuildBlobOpts, ) (*File, error)
BuildFileWithReader builds a file with a reader, building the root blob. The new root will be stored at bcs.
func NewFileWithBlob ¶
NewFileWithBlob builds a file with a single root blob.
func UnmarshalFile ¶
UnmarshalFile unmarshals the File block. Returns nil, nil if empty
func (*File) ApplySubBlock ¶
ApplySubBlock applies a sub-block change with a field id.
func (*File) BlockAliasIdentity ¶ added in v0.52.0
func (f *File) BlockAliasIdentity() *block.AliasIdentityToken
BlockAliasIdentity returns the in-memory alias token for File.
func (*File) CloneMessageVT ¶
func (m *File) CloneMessageVT() protobuf_go_lite.CloneMessage
func (*File) EqualMessageVT ¶
func (*File) GetRangeNonce ¶
func (*File) GetRootBlob ¶
func (*File) GetSubBlockCtor ¶
func (f *File) GetSubBlockCtor(id uint32) block.SubBlockCtor
GetSubBlockCtor returns a function which creates or returns the existing sub-block at reference id. Can return nil to indicate invalid reference id.
func (*File) GetSubBlocks ¶
GetSubBlocks returns all constructed sub-blocks by ID. May return nil, and values may also be nil.
func (*File) GetTotalSize ¶
func (*File) MarshalBlock ¶
MarshalBlock marshals the block to binary. This is the initial step of marshaling, before transformations.
func (*File) MarshalJSON ¶
MarshalJSON marshals the File to JSON.
func (*File) MarshalProtoJSON ¶
func (x *File) MarshalProtoJSON(s *json.MarshalState)
MarshalProtoJSON marshals the File message to JSON.
func (*File) MarshalProtoText ¶
func (*File) MarshalToSizedBufferVT ¶
func (*File) ProtoMessage ¶
func (*File) ProtoMessage()
func (*File) UnmarshalBlock ¶
UnmarshalBlock unmarshals the block to the object. This is the final step of decoding, after transformations.
func (*File) UnmarshalJSON ¶
UnmarshalJSON unmarshals the File from JSON.
func (*File) UnmarshalProtoJSON ¶
func (x *File) UnmarshalProtoJSON(s *json.UnmarshalState)
UnmarshalProtoJSON unmarshals the File message from JSON.
func (*File) UnmarshalVT ¶
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle is a open file handle, using a block transaction and a Not concurrency safe.
func (*Handle) ComputeStorageSize ¶
ComputeStorageSize computes the total size of all blocks making up the File.
note: not accurate until the btx has been committed.
func (*Handle) Read ¶
Read implements the reader interface. Read and Seek are not concurrent safe. It fills p across range boundaries until p is full, EOF is reached, or a selected blob reader stops making progress.
func (*Handle) Seek ¶
Seek implements the seeking interface. Seek sets the offset for the next Read or Write to offset, interpreted according to whence: SeekStart means relative to the start of the file, SeekCurrent means relative to the current offset, and SeekEnd means relative to the end. Seek returns the new offset relative to the start of the file and an error, if any.
Seeking to an offset before the start of the file is an error. Seeking to any positive offset is legal, but the behavior of subsequent Read and Seek are not concurrent safe.
type HandleRangeSlice ¶
type HandleRangeSlice struct {
// contains filtered or unexported fields
}
HandleRangeSlice is a sortable slice of ranges.
func NewHandleRangeSlice ¶
func NewHandleRangeSlice(h *Handle) *HandleRangeSlice
NewHandleRangeSlice builds a slice with a handle for sorting the block graph.
func (*HandleRangeSlice) Len ¶
func (r *HandleRangeSlice) Len() int
Len is the number of elements in the collection.
func (*HandleRangeSlice) Less ¶
func (r *HandleRangeSlice) Less(i, j int) bool
Less reports whether the element with index i should sort before the element with index j.
func (HandleRangeSlice) Swap ¶
func (r HandleRangeSlice) Swap(i, j int)
Swap swaps the elements with indexes i and j.
type Range ¶
type Range struct {
// Nonce is the incrementing nonce of the range.
// Ranges with a higher nonce overwrite lower nonce.
Nonce uint64 `protobuf:"varint,1,opt,name=nonce,proto3" json:"nonce,omitempty"`
// Start contains the starting index of the range.
Start uint64 `protobuf:"varint,2,opt,name=start,proto3" json:"start,omitempty"`
// Length contains the len of data in the range.
// Start + length = end index + 1.
Length uint64 `protobuf:"varint,3,opt,name=length,proto3" json:"length,omitempty"`
// Ref contains the blob ref.
// If the ref is empty, the range represents a hole (zeros).
Ref *block.BlockRef `protobuf:"bytes,4,opt,name=ref,proto3" json:"ref,omitempty"`
// contains filtered or unexported fields
}
Range contains a chunk of a file. Ranges are sorted by start, then nonce (ascending).
func (*Range) ApplyBlockRef ¶
ApplyBlockRef applies a ref change with a field id. The reference may be nil if the child block is nil.
func (*Range) BlockAliasIdentity ¶ added in v0.52.0
func (r *Range) BlockAliasIdentity() *block.AliasIdentityToken
BlockAliasIdentity returns the in-memory alias token for Range.
func (*Range) CloneMessageVT ¶
func (m *Range) CloneMessageVT() protobuf_go_lite.CloneMessage
func (*Range) EqualMessageVT ¶
func (*Range) FollowBlob ¶
FollowBlob follows the blob reference.
func (*Range) GetBlockRefCtor ¶
GetBlockRefCtor returns the constructor for the block at the ref id. Return nil to indicate invalid ref ID or unknown.
func (*Range) GetBlockRefs ¶
GetBlockRefs returns all block references by ID. May return nil, and values may also be nil. Note: this does not include pending references (in a cursor)
func (*Range) LessThanRange ¶
LessThanRange compares to ranges, returning true if r < other.
func (*Range) MarshalJSON ¶
MarshalJSON marshals the Range to JSON.
func (*Range) MarshalProtoJSON ¶
func (x *Range) MarshalProtoJSON(s *json.MarshalState)
MarshalProtoJSON marshals the Range message to JSON.
func (*Range) MarshalProtoText ¶
func (*Range) MarshalToSizedBufferVT ¶
func (*Range) ProtoMessage ¶
func (*Range) ProtoMessage()
func (*Range) UnmarshalJSON ¶
UnmarshalJSON unmarshals the Range from JSON.
func (*Range) UnmarshalProtoJSON ¶
func (x *Range) UnmarshalProtoJSON(s *json.UnmarshalState)
UnmarshalProtoJSON unmarshals the Range message from JSON.
func (*Range) UnmarshalVT ¶
type RangeSlice ¶
type RangeSlice []*Range
RangeSlice is a sortable slice of ranges.
func (RangeSlice) Len ¶
func (r RangeSlice) Len() int
Len is the number of elements in the collection.
func (RangeSlice) Less ¶
func (r RangeSlice) Less(i, j int) bool
Less reports whether the element with index i should sort before the element with index j.
func (RangeSlice) LocatePosition ¶
func (r RangeSlice) LocatePosition(pos int) (*Range, int, bool)
LocatePosition locates the range covering a position pos. returns the index of that range returns nil, 0, false if no range covering pos is located.
func (RangeSlice) Swap ¶
func (r RangeSlice) Swap(i, j int)
Swap swaps the elements with indexes i and j.
type Writer ¶
type Writer struct {
*Handle
// contains filtered or unexported fields
}
Writer is a handle that can write to a handle.
func NewWriter ¶
func NewWriter( h *Handle, btx *block.Transaction, buildBlobOpts *blob.BuildBlobOpts, ) *Writer
NewWriter builds a new writer handle. btx can be nil buildBlobOpts can be nil
func (*Writer) WriteBlob ¶
WriteBlob writes a blob to an index in a new range. Implies removing any ranges which are completely occluded.
func (*Writer) WriteBytes ¶
WriteBytes writes bytes to a blob and then to an index.