block.go 1.06 KB
Newer Older
1 2 3 4
package iface

import (
	"context"
Łukasz Magiera's avatar
Łukasz Magiera committed
5
	path "github.com/ipfs/interface-go-ipfs-core/path"
6 7
	"io"

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

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

	// Path returns path to the block
17
	Path() path.Resolved
18 19 20 21 22
}

// 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
23
	Put(context.Context, io.Reader, ...options.BlockPutOption) (BlockStat, error)
24 25

	// Get attempts to resolve the path and return a reader for data in the block
Łukasz Magiera's avatar
Łukasz Magiera committed
26
	Get(context.Context, path.Path) (io.Reader, error)
27 28 29 30 31 32

	// 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
Łukasz Magiera's avatar
Łukasz Magiera committed
33
	Rm(context.Context, path.Path, ...options.BlockRmOption) error
34 35

	// Stat returns information on
Łukasz Magiera's avatar
Łukasz Magiera committed
36
	Stat(context.Context, path.Path) (BlockStat, error)
37
}