提交 f6235c5c 作者: Juan Batiz-Benet 提交者: Brian Tiger Chow

importer: simplified splitter

The splitter is simplified using io.ReadFull, as this function
does exactly what we wanted.

I believe io.ErrUnexpectedEOF should be handled as an EOF here,
but please correct me if I'm wrong.
上级 706ebe8d
......@@ -28,28 +28,17 @@ func (ss *SizeSplitter) Split(r io.Reader) chan []byte {
for {
// log.Infof("making chunk with size: %d", ss.Size)
chunk := make([]byte, ss.Size)
sofar := 0
// this-chunk loop (keep reading until this chunk full)
for {
nread, err := r.Read(chunk[sofar:])
sofar += nread
if err == io.EOF {
if sofar > 0 {
// log.Infof("sending out chunk with size: %d", sofar)
out <- chunk[:sofar]
}
return
}
if err != nil {
log.Errorf("Block split error: %s", err)
return
}
if sofar == ss.Size {
// log.Infof("sending out chunk with size: %d", sofar)
out <- chunk[:sofar]
break // break out of this-chunk loop
}
nread, err := io.ReadFull(r, chunk)
if nread > 0 {
// log.Infof("sending out chunk with size: %d", sofar)
out <- chunk[:nread]
}
if err == io.EOF || err == io.ErrUnexpectedEOF {
return
}
if err != nil {
log.Errorf("Block split error: %s", err)
return
}
}
}()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论