car

package
v0.0.0-...-3423c7d Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package car implements the CARv1 file format.

Index

Constants

This section is empty.

Variables

View Source
var IdentityCID cid.Cid

IdentityCID is the "zero-length "identity" multihash with "raw" codec".

This is the best-practices placeholder value to refer to a non-existent or unknown object.

Functions

This section is empty.

Types

type Block

type Block struct {
	Length int
	Cid    cid.Cid
	Data   []byte
}

Block is a length-cid-data tuple. These make up most of CARv1.

See https://ipld.io/specs/transport/car/carv1/#data

func NewBlockFromCBOR

func NewBlockFromCBOR(node datamodel.Node, contentType uint64) (Block, error)

func NewBlockFromRaw

func NewBlockFromRaw(data []byte, contentType uint64) Block

NewBlockFromRaw creates a new CIDv1 with the given multicodec contentType on the fly.

func (Block) TotalLen

func (b Block) TotalLen() int

TotalLen returns the total length of the block, including the length prefix.

type OutStream

type OutStream interface {
	WriteBlock(Block) error
}

type Writer

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

Writer produces CARv1 files with size tracking.

The implementation is kinda memory-efficient. Needs up to IPLD block size plus peanuts of memory.

Rationale

github.com/ipld/go-car/v2 is not helpful because it wants to traverse a complete IPLD link system. However we create an IPLD link system (Merkle-DAG) on the fly in a single pass as we read the chain. CARv1 is simple enough that we can roll a custom block writer, so no big deal.

func NewWriter

func NewWriter(out io.Writer) (*Writer, error)

NewWriter creates a new CARv1 Writer and writes the header.

func (*Writer) Write

func (w *Writer) Write(data []byte) (n int, err error)

Write raw bytes to CAR.

func (*Writer) WriteBlock

func (w *Writer) WriteBlock(b Block) (err error)

WriteBlock writes out a length-CID-value tuple.

func (*Writer) Written

func (w *Writer) Written() int64

Written returns the number of bytes written so far.

Jump to

Keyboard shortcuts

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