car

package
v1.7.5 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2023 License: Apache-2.0, MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockInfo

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

BlockInfo keeps track of blocks in a CAR file

type BlockInfoCache

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

BlockInfoCache keeps block info by cid

func NewBlockInfoCache

func NewBlockInfoCache() *BlockInfoCache

func (*BlockInfoCache) Get

func (bic *BlockInfoCache) Get(c cid.Cid) (*BlockInfo, bool)

func (*BlockInfoCache) Put

func (bic *BlockInfoCache) Put(c cid.Cid, bi *BlockInfo)

type BlockInfoCacheManager

type BlockInfoCacheManager interface {
	// Get the BlockInfoCache by payload cid
	Get(payloadCid cid.Cid) *BlockInfoCache
	// Unref is called when a request no longer needs the cache.
	// If err is not nil, the data transfer failed.
	Unref(payloadCid cid.Cid, err error)
	// Close the block info cache manager
	Close() error
}

BlockInfoCacheManager gets a BlockInfoCache for a given payload cid. Implementations may wish to share the same cache between multiple requests for the same payload.

type CarOffsetWriter

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

CarOffsetWriter turns a blockstore and a root CID into a CAR file stream, starting from an offset. The traversal is depth-first. Other selectors are not yet supported.

func NewCarOffsetWriter

func NewCarOffsetWriter(payloadCid cid.Cid, bstore blockstore.Blockstore, blockInfos *BlockInfoCache) *CarOffsetWriter

func (*CarOffsetWriter) Write

func (s *CarOffsetWriter) Write(ctx context.Context, w io.Writer, writeOffset uint64) error

Write writes the CAR file to the writer, starting from writeOffset

type CarReaderSeeker

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

CarReaderSeeker wraps CarOffsetWriter with a ReadSeeker implementation. Note that the Read and Seek methods are not thread-safe. They must not be called concurrently with each other, but may be called concurrently with Cancel.

func NewCarReaderSeeker

func NewCarReaderSeeker(ctx context.Context, cow *CarOffsetWriter, size uint64) *CarReaderSeeker

func (*CarReaderSeeker) Cancel

func (c *CarReaderSeeker) Cancel(ctx context.Context) error

Cancel aborts any read operation: Once Cancel returns, all subsequent calls to Read() will return context.Canceled Thread-safe to call concurrently with Read.

func (*CarReaderSeeker) Read

func (c *CarReaderSeeker) Read(p []byte) (int, error)

Read reads data into the buffer. Not thread-safe to call concurrently with Seek or another Read. Thread-safe to call with Cancel.

func (*CarReaderSeeker) Seek

func (c *CarReaderSeeker) Seek(offset int64, whence int) (int64, error)

Seek changes the offset into the stream. Not thread-safe to call concurrently with Read, Cancel or another Seek. Should only be called once in the beginning before any Read call.

type DelayedUnrefBICM

type DelayedUnrefBICM struct {
	*RefCountBICM
	// contains filtered or unexported fields
}

DelayedUnrefBICM is like RefCountBCIM but if there was a data transfer error, the cache is not unrefed until after some delay. This is useful for the case where a connection goes down momentarily and then a new request is made (and we want to keep the cache for the new request).

func NewDelayedUnrefBICM

func NewDelayedUnrefBICM(unrefDelay time.Duration) *DelayedUnrefBICM

func (*DelayedUnrefBICM) Close

func (d *DelayedUnrefBICM) Close() error

func (*DelayedUnrefBICM) Unref

func (d *DelayedUnrefBICM) Unref(payloadCid cid.Cid, err error)

type RefCountBICM

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

RefCountBICM keeps track of references to a BlockInfoCache by payload cid, and deletes the cache once references reach zero.

func NewRefCountBICM

func NewRefCountBICM() *RefCountBICM

func (*RefCountBICM) Close

func (bm *RefCountBICM) Close() error

func (*RefCountBICM) Get

func (bm *RefCountBICM) Get(payloadCid cid.Cid) *BlockInfoCache

func (*RefCountBICM) Unref

func (bm *RefCountBICM) Unref(payloadCid cid.Cid, err error)

Jump to

Keyboard shortcuts

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