Improve handling of buffer size in Go client

This commit is contained in:
Kristóf Tóth 2019-04-17 17:07:08 +02:00
parent 024204e439
commit 7f08e01f39

View File

@ -2,9 +2,12 @@ package pipeio
import (
"os"
"io"
"bufio"
)
const defaultBufSize = 65536
type pipeReader struct {
pipe *os.File
@ -21,6 +24,7 @@ func NewPipeReader(pipePath string) (*pipeReader, error) {
if err != nil {
return nil, err
}
scanner.Buffer(make([]byte, defaultBufSize), defaultBufSize)
return &pipeReader{
pipe: pipe,
scanner: scanner,
@ -50,9 +54,16 @@ func (preader *pipeReader) RecvMessage() []byte {
if preader.scanner.Scan() {
return preader.scanner.Bytes()
}
if err := preader.scanner.Err(); err != io.EOF {
panic(err)
}
return nil
}
func (preader *pipeReader) BufSize(size int) {
preader.scanner.Buffer(make([]byte, size), size)
}
type pipeWriter struct {
pipe *os.File