Commit 0231080f authored by lash's avatar lash Committed by GitHub

Add join from chunks on disk (symmetric to bee-split) (#294)

parent 363dcd69
......@@ -13,6 +13,7 @@ import (
"github.com/ethersphere/bee/pkg/file"
"github.com/ethersphere/bee/pkg/file/joiner"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/spf13/cobra"
)
......@@ -23,6 +24,7 @@ var (
host string // flag variable, http api host
port int // flag variable, http api port
ssl bool // flag variable, uses https for api if set
indir string // flag variable, directory to retrieve chunks from
verbosity string // flag variable, debug level
logger logging.Logger
)
......@@ -70,8 +72,14 @@ func Join(cmd *cobra.Command, args []string) (err error) {
return err
}
// initialize interface with HTTP API
store := cmdfile.NewApiStore(host, port, ssl)
// initialize interface with backend store
// either from directory if set, or HTTP API if not set
var store storage.Getter
if indir != "" {
store = cmdfile.NewFsStore(indir)
} else {
store = cmdfile.NewApiStore(host, port, ssl)
}
// create the join and get its data reader
j := joiner.NewSimpleJoiner(store)
......@@ -95,6 +103,7 @@ Will output retrieved data to stdout.`,
c.Flags().StringVar(&host, "host", "127.0.0.1", "api host")
c.Flags().IntVar(&port, "port", 8080, "api port")
c.Flags().BoolVar(&ssl, "ssl", false, "use ssl")
c.Flags().StringVarP(&indir, "input-dir", "i", "", "retrieve chunks from directory")
c.Flags().StringVar(&verbosity, "info", "0", "log verbosity level 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=trace")
c.SetOutput(c.OutOrStdout())
......
......@@ -42,8 +42,8 @@ func (n *nopWriteCloser) Close() error {
return nil
}
// putGetter wraps both storage.Putter and storage.Getter interfaces
type putGetter interface {
// PutGetter wraps both storage.Putter and storage.Getter interfaces
type PutGetter interface {
storage.Putter
storage.Getter
}
......@@ -82,7 +82,7 @@ type FsStore struct {
}
// NewFsStore creates a new FsStore.
func NewFsStore(path string) storage.Putter {
func NewFsStore(path string) PutGetter {
return &FsStore{
path: path,
}
......@@ -101,6 +101,16 @@ func (f *FsStore) Put(ctx context.Context, mode storage.ModePut, chs ...swarm.Ch
return exist, nil
}
// Get implements storage.Getter.
func (f *FsStore) Get(ctx context.Context, mode storage.ModeGet, address swarm.Address) (ch swarm.Chunk, err error) {
chunkPath := filepath.Join(f.path, address.String())
data, err := ioutil.ReadFile(chunkPath)
if err != nil {
return nil, err
}
return swarm.NewChunk(address, data), nil
}
// ApiStore provies a storage.Putter that adds chunks to swarm through the HTTP chunk API.
type ApiStore struct {
Client *http.Client
......@@ -108,7 +118,7 @@ type ApiStore struct {
}
// NewApiStore creates a new ApiStore.
func NewApiStore(host string, port int, ssl bool) putGetter {
func NewApiStore(host string, port int, ssl bool) PutGetter {
scheme := "http"
if ssl {
scheme += "s"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment