github.com/ethersphere/bee/v2@v2.2.0/pkg/file/pipeline/pipeline.go (about)

     1  // Copyright 2020 The Swarm Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package pipeline
     6  
     7  import "io"
     8  
     9  // ChainWriter is a writer in a pipeline.
    10  // It is up to the implementer to decide whether a writer
    11  // calls the next writer or not. Implementers should
    12  // call the Sum method of the subsequent writer in case there
    13  // exists one.
    14  type ChainWriter interface {
    15  	ChainWrite(*PipeWriteArgs) error
    16  	Sum() ([]byte, error)
    17  }
    18  
    19  // Interface exposes an `io.Writer` and `Sum` method, for components to use as a black box.
    20  // Within a pipeline, writers are chainable. It is up for the implementer to decide whether
    21  // a writer calls the next writer. Implementers should always implement the `Sum` method
    22  // and call the next writer's `Sum` method (in case there is one), returning its result to
    23  // the calling context.
    24  type Interface interface {
    25  	io.Writer
    26  	Sum() ([]byte, error)
    27  }
    28  
    29  // PipeWriteArgs are passed between different ChainWriters.
    30  type PipeWriteArgs struct {
    31  	Ref  []byte // reference, generated by bmt
    32  	Key  []byte // encryption key
    33  	Span []byte // always unencrypted span uint64
    34  	Data []byte // data includes the span too, but it may be encrypted when the pipeline is encrypted
    35  }
    36  
    37  type PipelineFunc func() ChainWriter