storj.io/uplink@v1.13.0/private/storage/streams/splitter/splitter_segment.go (about)

     1  // Copyright (C) 2023 Storj Labs, Inc.
     2  // See LICENSE for copying information.
     3  
     4  package splitter
     5  
     6  import (
     7  	"io"
     8  
     9  	"storj.io/common/encryption"
    10  	"storj.io/common/storj"
    11  	"storj.io/uplink/private/metaclient"
    12  )
    13  
    14  type splitterSegment struct {
    15  	position   metaclient.SegmentPosition
    16  	encryption metaclient.SegmentEncryption
    17  	encParams  storj.EncryptionParameters
    18  	contentKey *storj.Key
    19  
    20  	maxSegmentSize int64
    21  	encTransformer encryption.Transformer
    22  	encBuf         *encryptedBuffer
    23  }
    24  
    25  func (s *splitterSegment) Begin() metaclient.BatchItem {
    26  	return &metaclient.BeginSegmentParams{
    27  		StreamID:      nil, // set by the stream batcher
    28  		Position:      s.position,
    29  		MaxOrderLimit: s.maxSegmentSize,
    30  	}
    31  }
    32  
    33  func (s *splitterSegment) Position() metaclient.SegmentPosition { return s.position }
    34  func (s *splitterSegment) Inline() bool                         { return false }
    35  func (s *splitterSegment) Reader() io.Reader                    { return s.encBuf.Reader() }
    36  func (s *splitterSegment) DoneReading(err error)                { s.encBuf.DoneReading(err) }
    37  
    38  func (s *splitterSegment) EncryptETag(eTag []byte) ([]byte, error) {
    39  	return encryptETag(eTag, s.encParams.CipherSuite, s.contentKey)
    40  }
    41  
    42  func (s *splitterSegment) Finalize() *SegmentInfo {
    43  	plainSize := s.encBuf.PlainSize()
    44  	return &SegmentInfo{
    45  		Encryption:    s.encryption,
    46  		PlainSize:     plainSize,
    47  		EncryptedSize: encryption.CalcTransformerEncryptedSize(plainSize, s.encTransformer),
    48  	}
    49  }