Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
interface-go-dms3-core
Commits
a7509ebf
Commit
a7509ebf
authored
Jan 06, 2018
by
Łukasz Magiera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coreapi: implement block API
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
parent
3cd2995b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
6 deletions
+67
-6
interface.go
interface.go
+7
-5
options/block.go
options/block.go
+60
-1
No files found.
interface.go
View file @
a7509ebf
...
@@ -62,6 +62,8 @@ type BlockStat interface {
...
@@ -62,6 +62,8 @@ type BlockStat interface {
type
CoreAPI
interface
{
type
CoreAPI
interface
{
// Unixfs returns an implementation of Unixfs API.
// Unixfs returns an implementation of Unixfs API.
Unixfs
()
UnixfsAPI
Unixfs
()
UnixfsAPI
// Block returns an implementation of Block API.
Block
()
BlockAPI
// Dag returns an implementation of Dag API.
// Dag returns an implementation of Dag API.
Dag
()
DagAPI
Dag
()
DagAPI
// Name returns an implementation of Name API.
// Name returns an implementation of Name API.
...
@@ -93,16 +95,16 @@ type UnixfsAPI interface {
...
@@ -93,16 +95,16 @@ type UnixfsAPI interface {
}
}
type
BlockAPI
interface
{
type
BlockAPI
interface
{
Put
(
context
.
Context
,
io
.
Reader
)
(
Path
,
error
)
Put
(
context
.
Context
,
io
.
Reader
,
...
options
.
BlockPutOption
)
(
Path
,
error
)
With
Codec
(
codec
uint64
)
options
.
BlockPutOption
With
Format
(
codec
string
)
options
.
BlockPutOption
WithHash
(
mhType
uint64
,
mhLen
int
)
options
.
BlockPutOption
WithHash
(
mhType
uint64
,
mhLen
int
)
options
.
BlockPutOption
Get
(
context
.
Context
)
(
io
.
Reader
,
error
)
Get
(
context
.
Context
,
Path
)
(
io
.
Reader
,
error
)
Rm
(
context
.
Context
)
error
Rm
(
context
.
Context
,
Path
,
...
options
.
BlockRmOption
)
error
WithForce
(
force
bool
)
options
.
BlockRmOption
WithForce
(
force
bool
)
options
.
BlockRmOption
Stat
(
context
.
Context
)
(
BlockStat
,
error
)
Stat
(
context
.
Context
,
Path
)
(
BlockStat
,
error
)
}
}
// DagAPI specifies the interface to IPLD
// DagAPI specifies the interface to IPLD
...
...
options/block.go
View file @
a7509ebf
package
options
package
options
import
(
//cid "gx/ipfs/QmeSrf6pzut73u6zLQkRFQ3ygt3k6XFT2kjdYP8Tnkwwyg/go-cid"
"gx/ipfs/QmYeKnKpubCMRiq3PGZcTREErthbb5Q9cXsCoSkD9bjEBd/go-multihash"
)
type
BlockPutSettings
struct
{
type
BlockPutSettings
struct
{
Codec
uint64
Codec
string
MhType
uint64
MhType
uint64
MhLength
int
MhLength
int
}
}
...
@@ -12,3 +17,57 @@ type BlockRmSettings struct {
...
@@ -12,3 +17,57 @@ type BlockRmSettings struct {
type
BlockPutOption
func
(
*
BlockPutSettings
)
error
type
BlockPutOption
func
(
*
BlockPutSettings
)
error
type
BlockRmOption
func
(
*
BlockRmSettings
)
error
type
BlockRmOption
func
(
*
BlockRmSettings
)
error
func
BlockPutOptions
(
opts
...
BlockPutOption
)
(
*
BlockPutSettings
,
error
)
{
options
:=
&
BlockPutSettings
{
Codec
:
"v0"
,
MhType
:
multihash
.
SHA2_256
,
MhLength
:
-
1
,
}
for
_
,
opt
:=
range
opts
{
err
:=
opt
(
options
)
if
err
!=
nil
{
return
nil
,
err
}
}
return
options
,
nil
}
func
BlockRmOptions
(
opts
...
BlockRmOption
)
(
*
BlockRmSettings
,
error
)
{
options
:=
&
BlockRmSettings
{
Force
:
false
,
}
for
_
,
opt
:=
range
opts
{
err
:=
opt
(
options
)
if
err
!=
nil
{
return
nil
,
err
}
}
return
options
,
nil
}
type
BlockOptions
struct
{}
func
(
api
*
BlockOptions
)
WithFormat
(
codec
string
)
BlockPutOption
{
return
func
(
settings
*
BlockPutSettings
)
error
{
settings
.
Codec
=
codec
return
nil
}
}
func
(
api
*
BlockOptions
)
WithHash
(
mhType
uint64
,
mhLen
int
)
BlockPutOption
{
return
func
(
settings
*
BlockPutSettings
)
error
{
settings
.
MhType
=
mhType
settings
.
MhLength
=
mhLen
return
nil
}
}
func
(
api
*
BlockOptions
)
WithForce
(
force
bool
)
BlockRmOption
{
return
func
(
settings
*
BlockRmSettings
)
error
{
settings
.
Force
=
force
return
nil
}
}
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