builder

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: Apache-2.0, MIT Imports: 27 Imported by: 19

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BlockSizeLimit = 1048576 // 1 MB

BlockSizeLimit specifies the maximum size an imported block can have.

View Source
var DefaultLinksPerBlock = roughLinkBlockSize / roughLinkSize

DefaultLinksPerBlock governs how the importer decides how many links there will be per block. This calculation is based on expected distributions of:

  • the expected distribution of block sizes
  • the expected distribution of link sizes
  • desired access speed

For now, we use:

var roughLinkBlockSize = 1 << 13 // 8KB
var roughLinkSize = 34 + 8 + 5   // sha256 multihash + size + no name
                                 // + protobuf framing
var DefaultLinksPerBlock = (roughLinkBlockSize / roughLinkSize)
                         = ( 8192 / 47 )
                         = (approximately) 174

Functions

func BlockSizes

func BlockSizes(b *Builder, blockSizes []uint64)

BlockSizes encodes block sizes for each child node

func BuildUnixFS

func BuildUnixFS(fn func(*Builder)) (data.UnixFSData, error)

BuildUnixFS provides a clean, validated interface to building data structures that match the UnixFS protobuf encoded in the Data member of a ProtoNode with sensible defaults

  smallFileData, err := BuildUnixFS(func(b *Builder) {
     Data(b, []byte{"hello world"})
     Mtime(b, func(tb TimeBuilder) {
				Time(tb, time.Now())
			})
  })

func BuildUnixFSDirectory

func BuildUnixFSDirectory(entries []dagpb.PBLink, ls *ipld.LinkSystem) (ipld.Link, uint64, error)

BuildUnixFSDirectory creates a directory link over a collection of entries.

func BuildUnixFSDirectoryEntry

func BuildUnixFSDirectoryEntry(name string, size int64, hash ipld.Link) (dagpb.PBLink, error)

BuildUnixFSDirectoryEntry creates the link to a file or directory as it appears within a unixfs directory.

func BuildUnixFSFile

func BuildUnixFSFile(r io.Reader, chunker string, ls *ipld.LinkSystem) (ipld.Link, uint64, error)

BuildUnixFSFile creates a dag of ipld Nodes representing file data. This recreates the functionality previously found in github.com/ipfs/go-unixfs/importer/balanced, but tailored to the go-unixfsnode & ipld-prime data layout of nodes. We make some assumptions in building files with this builder to reduce complexity, namely:

func BuildUnixFSRecursive

func BuildUnixFSRecursive(root string, ls *ipld.LinkSystem) (ipld.Link, uint64, error)

BuildUnixFSRecursive returns a link pointing to the UnixFS node representing the file or directory tree pointed to by `root`

func BuildUnixFSShardedDirectory

func BuildUnixFSShardedDirectory(size int, hasher uint64, entries []dagpb.PBLink, ls *ipld.LinkSystem) (ipld.Link, uint64, error)

BuildUnixFSShardedDirectory will build a hamt of unixfs hamt shards encoing a directory with more entries than is typically allowed to fit in a standard IPFS single-block unixFS directory.

func BuildUnixFSSymlink(content string, ls *ipld.LinkSystem) (ipld.Link, uint64, error)

BuildUnixFSSymlink builds a symlink entry in a unixfs tree

func Data

func Data(b *Builder, dataBytes []byte)

Data sets the data member inside the UnixFS data

func DataType

func DataType(b *Builder, dataType int64)

DataType sets the default on a builder for a UnixFS node - default is File

func Fanout

func Fanout(b *Builder, fanout uint64)

Fanout sets the fanout in a HAMT tree

func FileSize

func FileSize(b *Builder, fileSize uint64)

FileSize sets the file size which should be the size of actual bytes underneath this node for large files, w/o additional bytes to encode intermediate nodes

func FractionalNanoseconds

func FractionalNanoseconds(ma TimeBuilder, nanoseconds int32)

FractionalNanoseconds sets the nanoseconds for a modification time (must be between 0 & a billion)

func HashType

func HashType(b *Builder, hashType uint64)

HashType sets the hash function for this node -- only applicable to HAMT

func Mtime

func Mtime(b *Builder, fn func(tb TimeBuilder))

Mtime sets the modification time for this node using the time builder interface and associated methods

func Permissions

func Permissions(b *Builder, mode int)

Permissions sets file permissions for the Mode member of the UnixFS node

func PermissionsString

func PermissionsString(b *Builder, modeString string)

PermissionsString sets file permissions for the Mode member of the UnixFS node, parsed from a typical octect encoded permission string (eg '0755')

func Seconds

func Seconds(ma TimeBuilder, seconds int64)

Seconds sets the seconds for a modification time

func Time

func Time(ma TimeBuilder, t time.Time)

Time sets the modification time from a golang time value

Types

type Builder

type Builder struct {
	ipld.MapAssembler
	// contains filtered or unexported fields
}

Builder is an interface for making UnixFS data nodes

type TimeBuilder

type TimeBuilder ipld.MapAssembler

TimeBuilder is a simple interface for constructing the time member of UnixFS data

Directories

Path Synopsis
Package quickbuilder is designed as a replacement for the existing ipfs-files constructor for a simple way to generate synthetic directory trees.
Package quickbuilder is designed as a replacement for the existing ipfs-files constructor for a simple way to generate synthetic directory trees.

Jump to

Keyboard shortcuts

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