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
go-unixfs
Commits
dc6fdd39
Commit
dc6fdd39
authored
Oct 08, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use encoded (pretty) keys only on fs ds
parent
0ffc2038
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
5 deletions
+29
-5
core/datastore.go
core/datastore.go
+5
-1
util/util.go
util/util.go
+24
-4
No files found.
core/datastore.go
View file @
dc6fdd39
...
...
@@ -5,9 +5,12 @@ import (
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
fsds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/fs"
ktds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/keytransform"
lds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/leveldb"
syncds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/sync"
config
"github.com/jbenet/go-ipfs/config"
u
"github.com/jbenet/go-ipfs/util"
)
func
makeDatastore
(
cfg
config
.
Datastore
)
(
ds
.
ThreadSafeDatastore
,
error
)
{
...
...
@@ -28,7 +31,8 @@ func makeDatastore(cfg config.Datastore) (ds.ThreadSafeDatastore, error) {
if
err
!=
nil
{
return
nil
,
err
}
return
syncds
.
MutexWrap
(
d
),
nil
ktd
:=
ktds
.
WrapDatastore
(
d
,
u
.
DsKeyB58Encode
)
return
syncds
.
MutexWrap
(
ktd
),
nil
}
return
nil
,
fmt
.
Errorf
(
"Unknown datastore type: %s"
,
cfg
.
Type
)
...
...
util/util.go
View file @
dc6fdd39
...
...
@@ -55,14 +55,34 @@ func (k Key) Pretty() string {
// DsKey returns a Datastore key
func
(
k
Key
)
DsKey
()
ds
.
Key
{
return
ds
.
NewKey
(
k
.
Pretty
(
))
return
ds
.
NewKey
(
string
(
k
))
}
// KeyFromDsKey returns a Datastore key
func
KeyFromDsKey
(
dsk
ds
.
Key
)
Key
{
l
:=
dsk
.
List
()
enc
:=
l
[
len
(
l
)
-
1
]
return
Key
(
b58
.
Decode
(
enc
))
return
Key
(
dsk
.
BaseNamespace
())
}
// DsKeyB58Encode returns a B58 encoded Datastore key
// TODO: this is hacky because it encodes every path component. some
// path components may be proper strings already...
func
DsKeyB58Encode
(
dsk
ds
.
Key
)
ds
.
Key
{
k
:=
ds
.
NewKey
(
"/"
)
for
_
,
n
:=
range
dsk
.
Namespaces
()
{
k
=
k
.
Child
(
b58
.
Encode
([]
byte
(
n
)))
}
return
k
}
// DsKeyB58Decode returns a b58 decoded Datastore key
// TODO: this is hacky because it encodes every path component. some
// path components may be proper strings already...
func
DsKeyB58Decode
(
dsk
ds
.
Key
)
ds
.
Key
{
k
:=
ds
.
NewKey
(
"/"
)
for
_
,
n
:=
range
dsk
.
Namespaces
()
{
k
=
k
.
Child
(
string
(
b58
.
Decode
(
n
)))
}
return
k
}
// Hash is the global IPFS hash function. uses multihash SHA2_256, 256 bits
...
...
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