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-datastore
Commits
821e151c
Commit
821e151c
authored
Jun 22, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove hex encoding from flatfs
parent
6e446b05
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
18 deletions
+11
-18
flatfs/flatfs.go
flatfs/flatfs.go
+9
-16
flatfs/flatfs_test.go
flatfs/flatfs_test.go
+2
-2
No files found.
flatfs/flatfs.go
View file @
821e151c
...
@@ -4,7 +4,6 @@
...
@@ -4,7 +4,6 @@
package
flatfs
package
flatfs
import
(
import
(
"encoding/hex"
"errors"
"errors"
"io/ioutil"
"io/ioutil"
"os"
"os"
...
@@ -33,8 +32,8 @@ var (
...
@@ -33,8 +32,8 @@ var (
type
Datastore
struct
{
type
Datastore
struct
{
path
string
path
string
// length of the dir splay prefix
, in bytes of hex digits
// length of the dir splay prefix
hexP
refixLen
int
p
refixLen
int
// sychronize all writes and directory changes for added safety
// sychronize all writes and directory changes for added safety
sync
bool
sync
bool
...
@@ -48,20 +47,18 @@ func New(path string, prefixLen int, sync bool) (*Datastore, error) {
...
@@ -48,20 +47,18 @@ func New(path string, prefixLen int, sync bool) (*Datastore, error) {
}
}
fs
:=
&
Datastore
{
fs
:=
&
Datastore
{
path
:
path
,
path
:
path
,
// convert from binary bytes to bytes of hex encoding
prefixLen
:
prefixLen
,
hexPrefixLen
:
prefixLen
*
hex
.
EncodedLen
(
1
),
sync
:
sync
,
sync
:
sync
,
}
}
return
fs
,
nil
return
fs
,
nil
}
}
var
padding
=
strings
.
Repeat
(
"_"
,
maxPrefixLen
*
hex
.
EncodedLen
(
1
)
)
var
padding
=
strings
.
Repeat
(
"_"
,
maxPrefixLen
)
func
(
fs
*
Datastore
)
encode
(
key
datastore
.
Key
)
(
dir
,
file
string
)
{
func
(
fs
*
Datastore
)
encode
(
key
datastore
.
Key
)
(
dir
,
file
string
)
{
safe
:=
hex
.
EncodeToString
(
key
.
Bytes
()[
1
:
])
prefix
:=
(
key
.
String
()
+
padding
)[
:
fs
.
prefixLen
]
prefix
:=
(
safe
+
padding
)[
:
fs
.
hexPrefixLen
]
dir
=
path
.
Join
(
fs
.
path
,
prefix
)
dir
=
path
.
Join
(
fs
.
path
,
prefix
)
file
=
path
.
Join
(
dir
,
safe
+
extension
)
file
=
path
.
Join
(
dir
,
key
.
String
()
+
extension
)
return
dir
,
file
return
dir
,
file
}
}
...
@@ -70,11 +67,7 @@ func (fs *Datastore) decode(file string) (key datastore.Key, ok bool) {
...
@@ -70,11 +67,7 @@ func (fs *Datastore) decode(file string) (key datastore.Key, ok bool) {
return
datastore
.
Key
{},
false
return
datastore
.
Key
{},
false
}
}
name
:=
file
[
:
len
(
file
)
-
len
(
extension
)]
name
:=
file
[
:
len
(
file
)
-
len
(
extension
)]
k
,
err
:=
hex
.
DecodeString
(
name
)
return
datastore
.
NewKey
(
name
),
true
if
err
!=
nil
{
return
datastore
.
Key
{},
false
}
return
datastore
.
NewKey
(
string
(
k
)),
true
}
}
func
(
fs
*
Datastore
)
makePrefixDir
(
dir
string
)
error
{
func
(
fs
*
Datastore
)
makePrefixDir
(
dir
string
)
error
{
...
...
flatfs/flatfs_test.go
View file @
821e151c
...
@@ -152,8 +152,8 @@ func TestStorage(t *testing.T) {
...
@@ -152,8 +152,8 @@ func TestStorage(t *testing.T) {
defer
cleanup
()
defer
cleanup
()
const
prefixLen
=
2
const
prefixLen
=
2
const
prefix
=
"
7175
"
const
prefix
=
"
q
"
const
target
=
prefix
+
string
(
os
.
PathSeparator
)
+
"
71757578
.data"
const
target
=
prefix
+
string
(
os
.
PathSeparator
)
+
"
quux
.data"
fs
,
err
:=
flatfs
.
New
(
temp
,
prefixLen
,
false
)
fs
,
err
:=
flatfs
.
New
(
temp
,
prefixLen
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"New fail: %v
\n
"
,
err
)
t
.
Fatalf
(
"New fail: %v
\n
"
,
err
)
...
...
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