file.go 1.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright 2020 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package file provides interfaces for file-oriented operations.
package file

import (
	"context"
	"io"

	"github.com/ethersphere/bee/pkg/swarm"
)

15 16 17 18 19
type Reader interface {
	io.ReadSeeker
	io.ReaderAt
}

acud's avatar
acud committed
20 21 22
// Joiner provides the inverse functionality of the Splitter.
type Joiner interface {
	Reader
23 24
	// IterateChunkAddresses is used to iterate over chunks addresses of some root hash.
	IterateChunkAddresses(swarm.AddressIterFunc) error
acud's avatar
acud committed
25 26
	// Size returns the span of the hash trie represented by the joiner's root hash.
	Size() int64
27
}
28 29 30 31 32 33 34

// Splitter starts a new file splitting job.
//
// Data is read from the provided reader.
// If the dataLength parameter is 0, data is read until io.EOF is encountered.
// When EOF is received and splitting is done, the resulting Swarm Address is returned.
type Splitter interface {
35
	Split(ctx context.Context, dataIn io.ReadCloser, dataLength int64, toEncrypt bool) (addr swarm.Address, err error)
36
}