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-dms3-chunker
Commits
5bf56e97
Unverified
Commit
5bf56e97
authored
Sep 07, 2018
by
Steven Allen
Committed by
GitHub
Sep 07, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3 from kjzz/fix-chunker
return err when rabin min less than 16
parents
2c504457
b18fd483
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
1 deletion
+26
-1
parse.go
parse.go
+5
-1
parse_test.go
parse_test.go
+21
-0
No files found.
parse.go
View file @
5bf56e97
...
@@ -8,6 +8,8 @@ import (
...
@@ -8,6 +8,8 @@ import (
"strings"
"strings"
)
)
var
ErrRabinMin
=
errors
.
New
(
"rabin min must be greater than 16"
)
// FromString returns a Splitter depending on the given string:
// FromString returns a Splitter depending on the given string:
// it supports "default" (""), "size-{size}", "rabin", "rabin-{blocksize}" and
// it supports "default" (""), "size-{size}", "rabin", "rabin-{blocksize}" and
// "rabin-{min}-{avg}-{max}".
// "rabin-{min}-{avg}-{max}".
...
@@ -52,7 +54,9 @@ func parseRabinString(r io.Reader, chunker string) (Splitter, error) {
...
@@ -52,7 +54,9 @@ func parseRabinString(r io.Reader, chunker string) (Splitter, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
min
<
16
{
return
nil
,
ErrRabinMin
}
sub
=
strings
.
Split
(
parts
[
2
],
":"
)
sub
=
strings
.
Split
(
parts
[
2
],
":"
)
if
len
(
sub
)
>
1
&&
sub
[
0
]
!=
"avg"
{
if
len
(
sub
)
>
1
&&
sub
[
0
]
!=
"avg"
{
log
.
Error
(
"sub == "
,
sub
)
log
.
Error
(
"sub == "
,
sub
)
...
...
parse_test.go
0 → 100644
View file @
5bf56e97
package
chunk
import
(
"bytes"
"testing"
)
func
TestParse
(
t
*
testing
.
T
)
{
max
:=
1000
r
:=
bytes
.
NewReader
(
randBuf
(
t
,
max
))
chk1
:=
"rabin-18-25-32"
chk2
:=
"rabin-15-23-31"
_
,
err
:=
parseRabinString
(
r
,
chk1
)
if
err
!=
nil
{
t
.
Errorf
(
err
.
Error
())
}
_
,
err
=
parseRabinString
(
r
,
chk2
)
if
err
==
ErrRabinMin
{
t
.
Log
(
"it should be ErrRabinMin here."
)
}
}
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