block.go 1.01 KB
Newer Older
1 2 3 4 5 6
package iface

import (
	"context"
	"io"

Łukasz Magiera's avatar
Łukasz Magiera committed
7
	options "github.com/ipfs/interface-go-ipfs-core/options"
8 9 10 11 12 13 14 15
)

// BlockStat contains information about a block
type BlockStat interface {
	// Size is the size of a block
	Size() int

	// Path returns path to the block
16
	Path() ResolvedPath
17 18 19 20 21
}

// BlockAPI specifies the interface to the block layer
type BlockAPI interface {
	// Put imports raw block data, hashing it using specified settings.
Łukasz Magiera's avatar
Łukasz Magiera committed
22
	Put(context.Context, io.Reader, ...options.BlockPutOption) (BlockStat, error)
23 24 25 26 27 28 29 30 31 32 33 34 35 36

	// Get attempts to resolve the path and return a reader for data in the block
	Get(context.Context, Path) (io.Reader, error)

	// Rm removes the block specified by the path from local blockstore.
	// By default an error will be returned if the block can't be found locally.
	//
	// NOTE: If the specified block is pinned it won't be removed and no error
	// will be returned
	Rm(context.Context, Path, ...options.BlockRmOption) error

	// Stat returns information on
	Stat(context.Context, Path) (BlockStat, error)
}