forked from ethersphere/bee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline.go
37 lines (31 loc) · 1.28 KB
/
pipeline.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// 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 pipeline
import "io"
// ChainWriter is a writer in a pipeline.
// It is up to the implementer to decide whether a writer
// calls the next writer or not. Implementers should
// call the Sum method of the subsequent writer in case there
// exists one.
type ChainWriter interface {
ChainWrite(*PipeWriteArgs) error
Sum() ([]byte, error)
}
// Interface exposes an `io.Writer` and `Sum` method, for components to use as a black box.
// Within a pipeline, writers are chainable. It is up for the implementer to decide whether
// a writer calls the next writer. Implementers should always implement the `Sum` method
// and call the next writer's `Sum` method (in case there is one), returning its result to
// the calling context.
type Interface interface {
io.Writer
Sum() ([]byte, error)
}
// PipeWriteArgs are passed between different ChainWriters.
type PipeWriteArgs struct {
Ref []byte // reference, generated by bmt
Key []byte // encryption key
Span []byte // always unencrypted span uint64
Data []byte // data includes the span too, but it may be encrypted when the pipeline is encrypted
}
type PipelineFunc func() ChainWriter