filelogger to write output to a file

This commit is contained in:
Jae Kwon
2015-07-08 12:43:05 -07:00
parent 53a1cd2fbf
commit 28d7a21156
5 changed files with 74 additions and 22 deletions

View File

@ -1,14 +1,9 @@
package binary
import (
. "github.com/tendermint/tendermint/common"
"io"
)
const (
ByteSliceChunk = 1024
)
func WriteByteSlice(bz []byte, w io.Writer, n *int64, err *error) {
WriteVarint(len(bz), w, n, err)
WriteTo(bz, w, n, err)
@ -24,16 +19,8 @@ func ReadByteSlice(r io.Reader, n *int64, err *error) []byte {
return nil
}
var buf, tmpBuf []byte
// read one ByteSliceChunk at a time and append
for i := 0; i*ByteSliceChunk < length; i++ {
tmpBuf = make([]byte, MinInt(ByteSliceChunk, length-i*ByteSliceChunk))
ReadFull(tmpBuf, r, n, err)
if *err != nil {
return nil
}
buf = append(buf, tmpBuf...)
}
buf := make([]byte, length)
ReadFull(buf, r, n, err)
return buf
}