Provide interface to get stream size (#876)
## Description Allows kopia data collection consumers to query stream size. This is required for OneDrive that needs to set the file size prior to uploading file data. ## Type of change <!--- Please check the type of change your PR introduces: ---> - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Test - [ ] 💻 CI/Deployment - [x] 🐹 Trivial/Minor ## Issue(s) * #668 ## Test Plan <!-- How will this be tested prior to merging.--> - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
9e66f197c0
commit
ac638d3162
@ -22,7 +22,7 @@ type Collection interface {
|
||||
FullPath() path.Path
|
||||
}
|
||||
|
||||
// DataStream represents a single item within a DataCollection
|
||||
// Stream represents a single item within a Collection
|
||||
// that can be consumed as a stream (it embeds io.Reader)
|
||||
type Stream interface {
|
||||
// ToReader returns an io.Reader for the DataStream
|
||||
@ -31,8 +31,14 @@ type Stream interface {
|
||||
UUID() string
|
||||
}
|
||||
|
||||
// DataStreamInfo is used to provide service specific
|
||||
// information about the DataStream
|
||||
// StreamInfo is used to provide service specific
|
||||
// information about the Stream
|
||||
type StreamInfo interface {
|
||||
Info() details.ItemInfo
|
||||
}
|
||||
|
||||
// StreamSize is used to provide size
|
||||
// information about the Stream
|
||||
type StreamSize interface {
|
||||
Size() int64
|
||||
}
|
||||
|
||||
@ -38,6 +38,7 @@ func (kdc kopiaDataCollection) FullPath() path.Path {
|
||||
type kopiaDataStream struct {
|
||||
reader io.ReadCloser
|
||||
uuid string
|
||||
size int64
|
||||
}
|
||||
|
||||
func (kds kopiaDataStream) ToReader() io.ReadCloser {
|
||||
@ -47,3 +48,7 @@ func (kds kopiaDataStream) ToReader() io.ReadCloser {
|
||||
func (kds kopiaDataStream) UUID() string {
|
||||
return kds.uuid
|
||||
}
|
||||
|
||||
func (kds kopiaDataStream) Size() int64 {
|
||||
return kds.size
|
||||
}
|
||||
|
||||
@ -66,6 +66,7 @@ func (suite *KopiaDataCollectionUnitSuite) TestReturnsStreams() {
|
||||
&kopiaDataStream{
|
||||
reader: io.NopCloser(bytes.NewReader(testData[0])),
|
||||
uuid: uuids[0],
|
||||
size: int64(len(testData[0])),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -75,10 +76,12 @@ func (suite *KopiaDataCollectionUnitSuite) TestReturnsStreams() {
|
||||
&kopiaDataStream{
|
||||
reader: io.NopCloser(bytes.NewReader(testData[0])),
|
||||
uuid: uuids[0],
|
||||
size: int64(len(testData[0])),
|
||||
},
|
||||
&kopiaDataStream{
|
||||
reader: io.NopCloser(bytes.NewReader(testData[1])),
|
||||
uuid: uuids[1],
|
||||
size: int64(len(testData[1])),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -100,6 +103,9 @@ func (suite *KopiaDataCollectionUnitSuite) TestReturnsStreams() {
|
||||
buf, err := ioutil.ReadAll(returnedStream.ToReader())
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, buf, testData[count])
|
||||
require.Implements(t, (*data.StreamSize)(nil), returnedStream)
|
||||
ss := returnedStream.(data.StreamSize)
|
||||
assert.Equal(t, len(buf), int(ss.Size()))
|
||||
|
||||
count++
|
||||
}
|
||||
|
||||
@ -564,6 +564,7 @@ func restoreSingleItem(
|
||||
&kopiaDataStream{
|
||||
uuid: f.Name(),
|
||||
reader: r,
|
||||
size: f.Size(),
|
||||
},
|
||||
},
|
||||
path: itemDir,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user