mod

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2021 License: MIT Imports: 16 Imported by: 2

Documentation

Overview

Package mod provides DAG modification utilities to, for example, insert additional nodes in a unixfs DAG or truncate them.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSeekFail           = errors.New("failed to seek properly")
	ErrUnrecognizedWhence = errors.New("unrecognized whence")
	ErrNotUnixfs          = errors.New("dagmodifier only supports unixfs nodes (proto or raw)")
)

Common errors

Functions

func FileSize added in v0.4.8

func FileSize(n ipld.Node) (uint64, error)

Types

type DagModifier

type DagModifier struct {
	Prefix         cid.Prefix
	RawLeaves      bool
	BalancedFormat bool
	Maxlinks       int
	// contains filtered or unexported fields
}

DagModifier is the only struct licensed and able to correctly perform surgery on a DAG 'file' Dear god, please rename this to something more pleasant

func NewDagModifier

func NewDagModifier(ctx context.Context, from ipld.Node, serv ipld.DAGService, spl chunker.SplitterGen) (*DagModifier, error)

NewDagModifier returns a new DagModifier, the Cid prefix for newly created nodes will be inhered from the passed in node. If the Cid version if not 0 raw leaves will also be enabled. The Prefix and RawLeaves options can be overridden by changing them after the call.

func NewDagModifierBalanced added in v0.4.8

func NewDagModifierBalanced(ctx context.Context, from ipld.Node, serv ipld.DAGService, spl chunker.SplitterGen, ml int, noMeta bool) (*DagModifier, error)

func (*DagModifier) CtxReadFull

func (dm *DagModifier) CtxReadFull(ctx context.Context, b []byte) (int, error)

CtxReadFull reads data from this dag starting at the current offset

func (*DagModifier) GetCtx added in v0.4.8

func (dm *DagModifier) GetCtx() context.Context

func (*DagModifier) GetDserv added in v0.4.8

func (dm *DagModifier) GetDserv() ipld.DAGService

func (*DagModifier) GetNode

func (dm *DagModifier) GetNode() (ipld.Node, error)

GetNode gets the modified DAG Node

func (*DagModifier) HasChanges

func (dm *DagModifier) HasChanges() bool

HasChanges returned whether or not there are unflushed changes to this dag

func (*DagModifier) Read

func (dm *DagModifier) Read(b []byte) (int, error)

Read data from this dag starting at the current offset

func (*DagModifier) Seek

func (dm *DagModifier) Seek(offset int64, whence int) (int64, error)

Seek modifies the offset according to whence. See unixfs/io for valid whence values.

func (*DagModifier) Size

func (dm *DagModifier) Size() (int64, error)

Size returns the Filesize of the node

func (*DagModifier) Sync

func (dm *DagModifier) Sync() error

Sync writes changes to this dag to disk

func (*DagModifier) Truncate

func (dm *DagModifier) Truncate(size int64) error

Truncate truncates the current Node to 'size' and replaces it with the new one.

func (*DagModifier) Write

func (dm *DagModifier) Write(b []byte) (int, error)

Write continues writing to the dag at the current offset

func (*DagModifier) WriteAt

func (dm *DagModifier) WriteAt(b []byte, offset int64) (int, error)

WriteAt will modify a dag file in place

type MetaDagModifier added in v0.4.9

type MetaDagModifier struct {
	*DagModifier

	Overwrite bool
	// contains filtered or unexported fields
}

func NewMetaDagModifierBalanced added in v0.4.9

func NewMetaDagModifierBalanced(mod *DagModifier, db *help.DagBuilderHelper, overwrite bool) *MetaDagModifier

func (*MetaDagModifier) AddMetadata added in v0.4.9

func (mdm *MetaDagModifier) AddMetadata(root ipld.Node, metadata []byte) (ipld.Node, error)

AddMetadata puts the given `metadata` items to the given `root` that is the top node of a BTFS file DAG and returns a new root for the BTFS file DAG.

There are three scenarios possible: Scenario #1. No existing metadata for the `root`. So this scenario is

to create a new metadata sub-DAG.

Scenario #2. There are existing keys for the given `metadata` items.

Then this is to update the metadata sub-DAG with the given items.

Scenario #3. There are no pre-existing metadata items for the given `metadata` items.

Then this scenario is to append given items to the metadata sub-DAG.

TODO: trickle format Preconditions include that first the given `metadata` is in compact JSON format. Note that the given `metadata` should be added to the first element of the metadata list.

func (*MetaDagModifier) GetDb added in v0.4.9

func (mdm *MetaDagModifier) GetDb() *help.DagBuilderHelper

func (*MetaDagModifier) RemoveMetadata added in v0.4.9

func (mdm *MetaDagModifier) RemoveMetadata(root ipld.Node, metakeys []byte) (ipld.Node, error)

RemoveMetadata first truncate the metadata dag from the given `root`, update the metadata map with the given `metadata`, then calls meta-dag builder to create a metadata subDag and attach the metadata dag to a new root with the given `dataroot` being a child of the new root. The preconditions include that first the given `metadata` is a string with keys separated by commas, second`mdm.curNode` has the root of the metadata sub-DAG.

Jump to

Keyboard shortcuts

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