file

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFileNameMissing is returned when no file name was given.
	ErrFileNameMissing = errors.New("the first chunk should have the filename")

	// ErrNoSession is returned when no session id found for a given id.
	ErrNoSession = errors.New("no open file session with this id")

	// ErrUnauthorized is returned when a peer tries to access a file he
	// is not allowed to get
	ErrUnauthorized = errors.New("peer not authorized for requested file")
)

Functions

This section is empty.

Types

type Handler

type Handler interface {
	// BeginWrite creates an empty file.
	BeginWrite(ctx context.Context, fileName string) (uuid.UUID, error)

	// WriteChunk writes a chunk of data to a file identified by its ID.
	WriteChunk(ctx context.Context, sessionID uuid.UUID, chunk []byte) (err error)

	// EndWrite is called to finalize the file writing.
	EndWrite(ctx context.Context, sessionID uuid.UUID) (fileHash []byte, err error)

	// AbortWrite is called to abort the file writing process.
	AbortWrite(ctx context.Context, sessionID uuid.UUID) (err error)

	// ReadChunks reads a file by chunk and calls the callback for each chunk.
	ReadChunks(ctx context.Context, fileHash []byte, chunkSize int, reader Reader) error

	// Read returns the content of a file given its hash.
	Read(ctx context.Context, fileHash []byte) ([]byte, error)

	// Exists returns whether the file with the given hash exists in the handler db.
	Exists(ctx context.Context, fileHash []byte) (bool, error)
}

Handler contains the methods to handle a file on the Stratumn node.

func NewLocalFileHandler

func NewLocalFileHandler(path string, db db.DB) Handler

NewLocalFileHandler create a new file Handler.

type Reader

type Reader interface {
	OnChunk(chunk []byte, filePath string) error
}

Reader should be implemented by a type that wants to read a file by chunks.

Directories

Path Synopsis
Package mockhandler is a generated GoMock package.
Package mockhandler is a generated GoMock package.

Jump to

Keyboard shortcuts

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