store

package
v0.0.0-...-e23051b Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Finalize

func Finalize(writer io.WriterAt, header carv2.Header, idx *InsertionIndex, dataSize uint64, storeIdentityCIDs bool, indexCodec multicodec.Code) error

Finalize will write the index to the writer at the offset specified in the header. It should only be used for a CARv2 and when the CAR interface is being closed.

func FindCid

func FindCid(
	reader io.ReaderAt,
	idx index.Index,
	key cid.Cid,
	useWholeCids bool,
	zeroLenAsEOF bool,
	maxReadBytes uint64,
	readBytes bool,
) ([]byte, int64, int, error)

FindCid can be used to either up the existence, size and offset of a block if it exists in CAR as specified by the index; and optionally the data bytes of the block.

func Has

func Has(
	idx *InsertionIndex,
	c cid.Cid,
	maxIndexCidSize uint64,
	storeIdentityCIDs bool,
	blockstoreAllowDuplicatePuts bool,
	blockstoreUseWholeCIDs bool,
) (bool, error)

Has returns true if the block exists in in the store according to the various rules associated with the options. Similar to ShouldPut, but for the simpler Has() case.

func IsIdentity

func IsIdentity(key cid.Cid) (digest []byte, ok bool, err error)

IsIdentity inspects the CID and determines whether it is an IDENTITY CID.

func ResumableVersion

func ResumableVersion(reader io.Reader, writeAsV1 bool) error

ResumableVersion performs two tasks - check if there is a valid header at the start of the, reader, then check whether the version of that header matches what we expect.

func Resume

func Resume(
	rw ReaderWriterAt,
	dataReader io.ReaderAt,
	dataWriter *internalio.OffsetWriteSeeker,
	idx *InsertionIndex,
	roots []cid.Cid,
	dataOffset uint64,
	v1 bool,
	maxAllowedHeaderSize uint64,
	zeroLengthSectionAsEOF bool,
) error

Resume will attempt to resume a CARv2 or CARv1 file by checking that there exists an existing CAR and that the CAR header details match what is being requested for resumption. Resumption of a CARv2 involves "unfinalizing" the header by resetting it back to a bare state and then truncating the file to remove the index. Truncation is important because it allows a non-finalized CARv2 to be resumed from as the header won't contain the DataSize of the payload body and if the file also contains an index, we cannot determine the end of the payload. Therefore, when using a resumed, existing and finalized, CARv2, whose body may not extend beyond the index and then closing without finalization (e.g. due to a crash), the file will no longer be parseable because we won't have DataSize, and we won't be able to determine it by parsing the payload to EOF.

func ShouldPut

func ShouldPut(
	idx *InsertionIndex,
	c cid.Cid,
	maxIndexCidSize uint64,
	storeIdentityCIDs bool,
	blockstoreAllowDuplicatePuts bool,
	blockstoreUseWholeCIDs bool,
) (bool, error)

ShouldPut returns true if the block should be put into the CAR according to the options provided and the index. It returns false if the block should not be put into the CAR, either because it is an identity block and StoreIdentityCIDs is false, or because it already exists and BlockstoreAllowDuplicatePuts is false.

Types

type InsertionIndex

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

func NewInsertionIndex

func NewInsertionIndex() *InsertionIndex

func (*InsertionIndex) Codec

func (ii *InsertionIndex) Codec() multicodec.Code

func (*InsertionIndex) Flatten

func (ii *InsertionIndex) Flatten(codec multicodec.Code) (index.Index, error)

flatten returns a formatted index in the given codec for more efficient subsequent loading.

func (*InsertionIndex) ForEach

func (ii *InsertionIndex) ForEach(f func(multihash.Multihash, uint64) error) error

func (*InsertionIndex) ForEachCid

func (ii *InsertionIndex) ForEachCid(f func(cid.Cid, uint64) error) error

func (*InsertionIndex) Get

func (ii *InsertionIndex) Get(c cid.Cid) (uint64, error)

func (*InsertionIndex) GetAll

func (ii *InsertionIndex) GetAll(c cid.Cid, fn func(uint64) bool) error

func (*InsertionIndex) HasExactCID

func (ii *InsertionIndex) HasExactCID(c cid.Cid) (bool, error)

func (*InsertionIndex) HasMultihash

func (ii *InsertionIndex) HasMultihash(mh multihash.Multihash) (bool, error)

func (*InsertionIndex) InsertNoReplace

func (ii *InsertionIndex) InsertNoReplace(key cid.Cid, n uint64)

func (*InsertionIndex) Load

func (ii *InsertionIndex) Load(rs []index.Record) error

func (*InsertionIndex) Marshal

func (ii *InsertionIndex) Marshal(w io.Writer) (uint64, error)

func (*InsertionIndex) Unmarshal

func (ii *InsertionIndex) Unmarshal(r io.Reader) error

type ReaderWriterAt

type ReaderWriterAt interface {
	io.ReaderAt
	io.WriterAt
}

Jump to

Keyboard shortcuts

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