rclone/vendor/storj.io/uplink/private/metainfo/interface.go

84 lines
2.5 KiB
Go
Raw Normal View History

2020-05-11 20:57:46 +02:00
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package metainfo
2020-05-11 20:57:46 +02:00
import (
"context"
"time"
"storj.io/common/storj"
)
// CreateObject has optional parameters that can be set.
2020-05-11 20:57:46 +02:00
type CreateObject struct {
Metadata map[string]string
ContentType string
Expires time.Time
storj.RedundancyScheme
storj.EncryptionParameters
}
// Object converts the CreateObject to an object with unitialized values.
2020-05-11 20:57:46 +02:00
func (create CreateObject) Object(bucket storj.Bucket, path storj.Path) storj.Object {
return storj.Object{
Bucket: bucket,
Path: path,
Metadata: create.Metadata,
ContentType: create.ContentType,
Expires: create.Expires,
Stream: storj.Stream{
Size: -1, // unknown
Checksum: nil, // unknown
SegmentCount: -1, // unknown
FixedSegmentSize: -1, // unknown
RedundancyScheme: create.RedundancyScheme,
EncryptionParameters: create.EncryptionParameters,
},
}
}
// ReadOnlyStream is an interface for reading segment information.
2020-05-11 20:57:46 +02:00
type ReadOnlyStream interface {
Info() storj.Object
// SegmentsAt returns the segment that contains the byteOffset and following segments.
// Limit specifies how much to return at most.
SegmentsAt(ctx context.Context, byteOffset int64, limit int64) (infos []storj.Segment, more bool, err error)
// Segments returns the segment at index.
// Limit specifies how much to return at most.
Segments(ctx context.Context, index int64, limit int64) (infos []storj.Segment, more bool, err error)
}
// MutableObject is an interface for manipulating creating/deleting object stream.
2020-05-11 20:57:46 +02:00
type MutableObject interface {
// Info gets the current information about the object.
2020-05-11 20:57:46 +02:00
Info() storj.Object
// CreateStream creates a new stream for the object.
2020-05-11 20:57:46 +02:00
CreateStream(ctx context.Context) (MutableStream, error)
// ContinueStream starts to continue a partially uploaded stream.
ContinueStream(ctx context.Context) (MutableStream, error)
// DeleteStream deletes any information about this objects stream.
2020-05-11 20:57:46 +02:00
DeleteStream(ctx context.Context) error
// Commit commits the changes to the database.
2020-05-11 20:57:46 +02:00
Commit(ctx context.Context) error
}
// MutableStream is an interface for manipulating stream information.
2020-05-11 20:57:46 +02:00
type MutableStream interface {
BucketName() string
Path() string
Expires() time.Time
Metadata() ([]byte, error)
// AddSegments adds segments to the stream.
AddSegments(ctx context.Context, segments ...storj.Segment) error
// UpdateSegments updates information about segments.
UpdateSegments(ctx context.Context, segments ...storj.Segment) error
}