Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
0231080f
Unverified
Commit
0231080f
authored
Jun 15, 2020
by
lash
Committed by
GitHub
Jun 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add join from chunks on disk (symmetric to bee-split) (#294)
parent
363dcd69
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
6 deletions
+25
-6
main.go
cmd/bee-join/main.go
+11
-2
io.go
cmd/internal/file/io.go
+14
-4
No files found.
cmd/bee-join/main.go
View file @
0231080f
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
"github.com/ethersphere/bee/pkg/file"
"github.com/ethersphere/bee/pkg/file"
"github.com/ethersphere/bee/pkg/file/joiner"
"github.com/ethersphere/bee/pkg/file/joiner"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
)
)
...
@@ -23,6 +24,7 @@ var (
...
@@ -23,6 +24,7 @@ var (
host
string
// flag variable, http api host
host
string
// flag variable, http api host
port
int
// flag variable, http api port
port
int
// flag variable, http api port
ssl
bool
// flag variable, uses https for api if set
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
verbosity
string
// flag variable, debug level
logger
logging
.
Logger
logger
logging
.
Logger
)
)
...
@@ -70,8 +72,14 @@ func Join(cmd *cobra.Command, args []string) (err error) {
...
@@ -70,8 +72,14 @@ func Join(cmd *cobra.Command, args []string) (err error) {
return
err
return
err
}
}
// initialize interface with HTTP API
// initialize interface with backend store
store
:=
cmdfile
.
NewApiStore
(
host
,
port
,
ssl
)
// 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
// create the join and get its data reader
j
:=
joiner
.
NewSimpleJoiner
(
store
)
j
:=
joiner
.
NewSimpleJoiner
(
store
)
...
@@ -95,6 +103,7 @@ Will output retrieved data to stdout.`,
...
@@ -95,6 +103,7 @@ Will output retrieved data to stdout.`,
c
.
Flags
()
.
StringVar
(
&
host
,
"host"
,
"127.0.0.1"
,
"api host"
)
c
.
Flags
()
.
StringVar
(
&
host
,
"host"
,
"127.0.0.1"
,
"api host"
)
c
.
Flags
()
.
IntVar
(
&
port
,
"port"
,
8080
,
"api port"
)
c
.
Flags
()
.
IntVar
(
&
port
,
"port"
,
8080
,
"api port"
)
c
.
Flags
()
.
BoolVar
(
&
ssl
,
"ssl"
,
false
,
"use ssl"
)
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
.
Flags
()
.
StringVar
(
&
verbosity
,
"info"
,
"0"
,
"log verbosity level 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=trace"
)
c
.
SetOutput
(
c
.
OutOrStdout
())
c
.
SetOutput
(
c
.
OutOrStdout
())
...
...
cmd/internal/file/io.go
View file @
0231080f
...
@@ -42,8 +42,8 @@ func (n *nopWriteCloser) Close() error {
...
@@ -42,8 +42,8 @@ func (n *nopWriteCloser) Close() error {
return
nil
return
nil
}
}
//
p
utGetter wraps both storage.Putter and storage.Getter interfaces
//
P
utGetter wraps both storage.Putter and storage.Getter interfaces
type
p
utGetter
interface
{
type
P
utGetter
interface
{
storage
.
Putter
storage
.
Putter
storage
.
Getter
storage
.
Getter
}
}
...
@@ -82,7 +82,7 @@ type FsStore struct {
...
@@ -82,7 +82,7 @@ type FsStore struct {
}
}
// NewFsStore creates a new FsStore.
// NewFsStore creates a new FsStore.
func
NewFsStore
(
path
string
)
storage
.
Pu
tter
{
func
NewFsStore
(
path
string
)
PutGe
tter
{
return
&
FsStore
{
return
&
FsStore
{
path
:
path
,
path
:
path
,
}
}
...
@@ -101,6 +101,16 @@ func (f *FsStore) Put(ctx context.Context, mode storage.ModePut, chs ...swarm.Ch
...
@@ -101,6 +101,16 @@ func (f *FsStore) Put(ctx context.Context, mode storage.ModePut, chs ...swarm.Ch
return
exist
,
nil
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.
// ApiStore provies a storage.Putter that adds chunks to swarm through the HTTP chunk API.
type
ApiStore
struct
{
type
ApiStore
struct
{
Client
*
http
.
Client
Client
*
http
.
Client
...
@@ -108,7 +118,7 @@ type ApiStore struct {
...
@@ -108,7 +118,7 @@ type ApiStore struct {
}
}
// NewApiStore creates a new ApiStore.
// NewApiStore creates a new ApiStore.
func
NewApiStore
(
host
string
,
port
int
,
ssl
bool
)
p
utGetter
{
func
NewApiStore
(
host
string
,
port
int
,
ssl
bool
)
P
utGetter
{
scheme
:=
"http"
scheme
:=
"http"
if
ssl
{
if
ssl
{
scheme
+=
"s"
scheme
+=
"s"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment