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
73797622
Commit
73797622
authored
Dec 19, 2017
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't waste 256KiB buffers on small chunks.
License: MIT Signed-off-by:
Steven Allen
<
steven@stebalien.com
>
parent
2a5b689c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
10 deletions
+16
-10
splitting.go
splitting.go
+16
-10
No files found.
splitting.go
View file @
73797622
...
...
@@ -5,6 +5,7 @@ import (
"io"
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
mpool
"gx/ipfs/QmWBug6eBS7AxRdCDVuSY5CnSit7cS2XnPFYJWqWDumhCG/go-msgio/mpool"
)
var
log
=
logging
.
Logger
(
"chunk"
)
...
...
@@ -51,14 +52,14 @@ func Chan(s Splitter) (<-chan []byte, <-chan error) {
type
sizeSplitterv2
struct
{
r
io
.
Reader
size
int
64
size
u
int
32
err
error
}
func
NewSizeSplitter
(
r
io
.
Reader
,
size
int64
)
Splitter
{
return
&
sizeSplitterv2
{
r
:
r
,
size
:
size
,
size
:
uint32
(
size
)
,
}
}
...
...
@@ -66,17 +67,22 @@ func (ss *sizeSplitterv2) NextBytes() ([]byte, error) {
if
ss
.
err
!=
nil
{
return
nil
,
ss
.
err
}
buf
:=
make
([]
byte
,
ss
.
size
)
n
,
err
:=
io
.
ReadFull
(
ss
.
r
,
buf
)
if
err
==
io
.
ErrUnexpectedEOF
{
full
:=
mpool
.
ByteSlicePool
.
Get
(
ss
.
size
)
.
([]
byte
)[
:
ss
.
size
]
n
,
err
:=
io
.
ReadFull
(
ss
.
r
,
full
)
switch
err
{
case
io
.
ErrUnexpectedEOF
:
ss
.
err
=
io
.
EOF
err
=
nil
}
if
err
!=
nil
{
small
:=
make
([]
byte
,
n
)
copy
(
small
,
full
)
mpool
.
ByteSlicePool
.
Put
(
ss
.
size
,
full
)
return
small
,
nil
case
nil
:
return
full
,
nil
default
:
mpool
.
ByteSlicePool
.
Put
(
ss
.
size
,
full
)
return
nil
,
err
}
return
buf
[
:
n
],
nil
}
func
(
ss
*
sizeSplitterv2
)
Reader
()
io
.
Reader
{
...
...
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