2018-07-27 19:13:08 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package streams
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"storj.io/storj/pkg/paths"
|
|
|
|
"storj.io/storj/pkg/ranger"
|
|
|
|
"storj.io/storj/pkg/storage/segments"
|
|
|
|
)
|
|
|
|
|
2018-07-30 19:57:50 +01:00
|
|
|
// Passthrough implementation of stream store
|
2018-07-27 19:13:08 +01:00
|
|
|
type Passthrough struct {
|
|
|
|
Segments segments.Store
|
|
|
|
}
|
|
|
|
|
2018-07-30 19:57:50 +01:00
|
|
|
// NewPassthrough stream store
|
2018-07-27 19:13:08 +01:00
|
|
|
func NewPassthrough(s segments.Store) *Passthrough {
|
|
|
|
return &Passthrough{Segments: s}
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ Store = (*Passthrough)(nil)
|
|
|
|
|
2018-07-30 19:57:50 +01:00
|
|
|
// Meta implements Store.Meta
|
|
|
|
func (p *Passthrough) Meta(ctx context.Context, path paths.Path) (Meta, error) {
|
2018-07-27 19:13:08 +01:00
|
|
|
m, err := p.Segments.Meta(ctx, path)
|
|
|
|
return convertMeta(m), err
|
|
|
|
}
|
|
|
|
|
2018-07-30 19:57:50 +01:00
|
|
|
// Get implements Store.Get
|
2018-07-27 19:13:08 +01:00
|
|
|
func (p *Passthrough) Get(ctx context.Context, path paths.Path) (
|
2018-07-30 19:57:50 +01:00
|
|
|
ranger.RangeCloser, Meta, error) {
|
2018-07-27 19:13:08 +01:00
|
|
|
rr, m, err := p.Segments.Get(ctx, path)
|
|
|
|
return rr, convertMeta(m), err
|
|
|
|
}
|
|
|
|
|
2018-07-30 19:57:50 +01:00
|
|
|
// Put implements Store.Put
|
2018-07-27 19:13:08 +01:00
|
|
|
func (p *Passthrough) Put(ctx context.Context, path paths.Path, data io.Reader,
|
2018-07-30 19:57:50 +01:00
|
|
|
metadata []byte, expiration time.Time) (Meta, error) {
|
2018-07-27 19:13:08 +01:00
|
|
|
m, err := p.Segments.Put(ctx, path, data, metadata, expiration)
|
|
|
|
return convertMeta(m), err
|
|
|
|
}
|
|
|
|
|
2018-07-30 19:57:50 +01:00
|
|
|
// Delete implements Store.Delete
|
2018-07-27 19:13:08 +01:00
|
|
|
func (p *Passthrough) Delete(ctx context.Context, path paths.Path) error {
|
|
|
|
return p.Segments.Delete(ctx, path)
|
|
|
|
}
|
|
|
|
|
2018-07-30 19:57:50 +01:00
|
|
|
// List implements Store.List
|
2018-07-27 19:13:08 +01:00
|
|
|
func (p *Passthrough) List(ctx context.Context,
|
|
|
|
prefix, startAfter, endBefore paths.Path, recursive bool, limit int,
|
2018-07-30 19:57:50 +01:00
|
|
|
metaFlags uint32) (items []ListItem, more bool, err error) {
|
|
|
|
segItems, more, err := p.Segments.List(ctx, prefix, startAfter, endBefore,
|
|
|
|
recursive, limit, metaFlags)
|
|
|
|
if err != nil {
|
|
|
|
return nil, false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
items = make([]ListItem, len(segItems))
|
|
|
|
for i, itm := range segItems {
|
|
|
|
items[i] = ListItem{
|
|
|
|
Path: itm.Path,
|
|
|
|
Meta: convertMeta(itm.Meta),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return items, more, nil
|
2018-07-27 19:13:08 +01:00
|
|
|
}
|
|
|
|
|
2018-07-30 19:57:50 +01:00
|
|
|
// convertMeta converts segment metadata to stream metadata
|
|
|
|
func convertMeta(m segments.Meta) Meta {
|
|
|
|
return Meta{
|
|
|
|
Modified: m.Modified,
|
|
|
|
Expiration: m.Expiration,
|
|
|
|
Size: m.Size,
|
|
|
|
Data: m.Data,
|
|
|
|
}
|
2018-07-27 19:13:08 +01:00
|
|
|
}
|