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

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