Skip to content

Commit

Permalink
Merge d8662ca into 05cd76d
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloyan-raev committed Jul 12, 2018
2 parents 05cd76d + d8662ca commit 06504dc
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/storage/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.

package storage

import (
"storj.io/storj/pkg/paths"
)

// ListItem is a single item in a listing
type ListItem struct {
path paths.Path
meta Meta
}
20 changes: 20 additions & 0 deletions pkg/storage/meta.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.

package storage

import (
"time"
)

// Meta info
type Meta struct {
Size int64
Modified time.Time
Expiration time.Time
ContentType string
Checksum string
// Redundancy eestream.RedundancyStrategy
// EncryptionScheme
Data []byte
}
81 changes: 81 additions & 0 deletions pkg/storage/objects/store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.

package objects

import (
"context"
"io"
"time"

monkit "gopkg.in/spacemonkeygo/monkit.v2"

"storj.io/storj/pkg/paths"
"storj.io/storj/pkg/ranger"
"storj.io/storj/pkg/storage"
"storj.io/storj/pkg/storage/streams"
)

var mon = monkit.Package()

// Store for objects
type Store interface {
Meta(ctx context.Context, path paths.Path) (meta storage.Meta, err error)
Get(ctx context.Context, path paths.Path) (rr ranger.RangeCloser,
meta storage.Meta, err error)
Put(ctx context.Context, path paths.Path, data io.Reader, metadata []byte,
expiration time.Time) (meta storage.Meta, err error)
Delete(ctx context.Context, path paths.Path) (err error)
List(ctx context.Context, root, startAfter, endBefore paths.Path,
recursive bool, limit int, metaFlags uint64) (items []paths.Path,
more bool, err error)
}

type objStore struct {
s streams.Store
}

// NewStore for objects
func NewStore(store streams.Store) Store {
return &objStore{s: store}
}

func (o *objStore) Meta(ctx context.Context, path paths.Path) (
meta storage.Meta, err error) {
defer mon.Task()(&ctx)(&err)
objPath := getDefautStreamPath(path)
return o.s.Meta(ctx, objPath)
}

func (o *objStore) Get(ctx context.Context, path paths.Path) (
rr ranger.RangeCloser, meta storage.Meta, err error) {
defer mon.Task()(&ctx)(&err)
objPath := getDefautStreamPath(path)
return o.s.Get(ctx, objPath)
}

func (o *objStore) Put(ctx context.Context, path paths.Path, data io.Reader,
metadata []byte, expiration time.Time) (meta storage.Meta, err error) {
defer mon.Task()(&ctx)(&err)
objPath := getDefautStreamPath(path)
return o.s.Put(ctx, objPath, data, metadata, expiration)
}

func (o *objStore) Delete(ctx context.Context, path paths.Path) (err error) {
defer mon.Task()(&ctx)(&err)
objPath := getDefautStreamPath(path)
return o.s.Delete(ctx, objPath)
}

func (o *objStore) List(ctx context.Context, root, startAfter,
endBefore paths.Path, recursive bool, limit int, metaFlags uint64) (
items []paths.Path, more bool, err error) {
defer mon.Task()(&ctx)(&err)
rootObjPath := getDefautStreamPath(root)
return o.s.List(ctx, rootObjPath, startAfter, endBefore, recursive, limit,
metaFlags)
}

func getDefautStreamPath(path paths.Path) paths.Path {
return path.Prepend("object")
}
27 changes: 27 additions & 0 deletions pkg/storage/streams/store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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"
)

// Store for streams
type Store interface {
Meta(ctx context.Context, path paths.Path) (storage.Meta, error)
Get(ctx context.Context, path paths.Path) (ranger.RangeCloser,
storage.Meta, error)
Put(ctx context.Context, path paths.Path, data io.Reader, metadata []byte,
expiration time.Time) (storage.Meta, error)
Delete(ctx context.Context, path paths.Path) error
List(ctx context.Context, root, startAfter, endBefore paths.Path,
recursive bool, limit int, metaFlags uint64) (items []paths.Path,
more bool, err error)
}

0 comments on commit 06504dc

Please sign in to comment.