storj/lib/uplink/object.go
JT Olio d7f3a5f811
internal,lib,uplink: add monkit task to missing places (#2118)
* internal,lib,uplink: add monkit task to missing places

Change-Id: I490053eee4ed517502f9fe00c6394f0095bd13d0

* Include Monkit

* Add missing context

* Another missing ctx

* More ctx missing

* Linting

* go imports

Change-Id: Ibf0ed072eba339f027727ed8039f7bce1f223fa7

* fix semantic merge conflict

Change-Id: I67fb1f4e7b6cd5e89d69987ed7b3966b7d30ee37
2019-06-05 09:03:11 -06:00

108 lines
3.3 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package uplink
import (
"context"
"io"
"time"
"storj.io/storj/internal/readcloser"
"storj.io/storj/pkg/metainfo/kvmetainfo"
"storj.io/storj/pkg/storage/streams"
"storj.io/storj/pkg/storj"
"storj.io/storj/pkg/stream"
)
// ObjectMeta contains metadata about a specific Object
type ObjectMeta struct {
// Bucket gives the name of the bucket in which an Object is placed.
Bucket string
// Path is the path of the Object within the Bucket. Path components are
// forward-slash-separated, like Unix file paths ("one/two/three").
Path storj.Path
// IsPrefix is true if this ObjectMeta does not refer to a specific
// Object, but to some arbitrary point in the path hierarchy. This would
// be called a "folder" or "directory" in a typical filesystem.
IsPrefix bool
// ContentType, if set, gives a MIME content-type for the Object, as
// set when the object was created.
ContentType string
// Metadata contains the additional information about an Object that was
// set when the object was created. See UploadOptions.Metadata for more
// information.
Metadata map[string]string
// Created is the time at which the Object was created.
Created time.Time
// Modified is the time at which the Object was last modified.
Modified time.Time
// Expires is the time at which the Object expires (after which it will
// be automatically deleted from storage nodes).
Expires time.Time
// Size gives the size of the Object in bytes.
Size int64
// Checksum gives a checksum of the contents of the Object.
Checksum []byte
// Volatile groups config values that are likely to change semantics
// or go away entirely between releases. Be careful when using them!
Volatile struct {
// EncryptionParameters gives the encryption parameters being
// used for the Object's data encryption.
EncryptionParameters storj.EncryptionParameters
// RedundancyScheme determines the Reed-Solomon and/or Forward
// Error Correction encoding parameters to be used for this
// Object.
RedundancyScheme storj.RedundancyScheme
// SegmentsSize gives the segment size being used for the
// Object's data storage.
SegmentsSize int64
}
}
// An Object is a sequence of bytes with associated metadata, stored in the
// Storj network (or being prepared for such storage). It belongs to a specific
// bucket, and has a path and a size. It is comparable to a "file" in a
// conventional filesystem.
type Object struct {
// Meta holds the metainfo associated with the Object.
Meta ObjectMeta
metainfoDB *kvmetainfo.DB
streams streams.Store
}
// DownloadRange returns an Object's data. A length of -1 will mean
// (Object.Size - offset).
func (o *Object) DownloadRange(ctx context.Context, offset, length int64) (_ io.ReadCloser, err error) {
defer mon.Task()(&ctx)(&err)
readOnlyStream, err := o.metainfoDB.GetObjectStream(ctx, o.Meta.Bucket, o.Meta.Path)
if err != nil {
return nil, err
}
download := stream.NewDownload(ctx, readOnlyStream, o.streams)
_, err = download.Seek(offset, io.SeekStart)
if err != nil {
return nil, err
}
if length == -1 {
return download, nil
}
return readcloser.LimitReadCloser(download, length), nil
}
// Close closes the Object.
func (o *Object) Close() error {
return nil
}