Fixed edge case where the beginnings of messages would sometimes get chopped off as a result of creating a new buffered reader each time we'd read a line.
This commit is contained in:
parent
d63effaddd
commit
22915133fe
1 changed files with 11 additions and 9 deletions
20
kcl/kcl.go
20
kcl/kcl.go
|
|
@ -23,11 +23,19 @@ type Checkpointer interface {
|
|||
}
|
||||
|
||||
type ioHandler struct {
|
||||
inputFile io.Reader
|
||||
input *bufio.Reader
|
||||
outputFile io.Writer
|
||||
errorFile io.Writer
|
||||
}
|
||||
|
||||
func newIOHandler(inputFile io.Reader, outputFile, errorFile io.Writer) ioHandler {
|
||||
return ioHandler{
|
||||
input: bufio.NewReader(inputFile),
|
||||
outputFile: outputFile,
|
||||
errorFile: errorFile,
|
||||
}
|
||||
}
|
||||
|
||||
func (i ioHandler) writeLine(line string) {
|
||||
fmt.Fprintf(i.outputFile, "\n%s\n", line)
|
||||
}
|
||||
|
|
@ -37,8 +45,7 @@ func (i ioHandler) writeError(message string) {
|
|||
}
|
||||
|
||||
func (i ioHandler) readLine() (string, error) {
|
||||
bio := bufio.NewReader(i.inputFile)
|
||||
line, err := bio.ReadString('\n')
|
||||
line, err := i.input.ReadString('\n')
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
@ -130,13 +137,8 @@ func (i ioHandler) writeAction(action interface{}) error {
|
|||
func New(
|
||||
inputFile io.Reader, outputFile, errorFile io.Writer, recordProcessor RecordProcessor,
|
||||
) *KCLProcess {
|
||||
i := ioHandler{
|
||||
inputFile: inputFile,
|
||||
outputFile: outputFile,
|
||||
errorFile: errorFile,
|
||||
}
|
||||
return &KCLProcess{
|
||||
ioHandler: i,
|
||||
ioHandler: newIOHandler(inputFile, outputFile, errorFile),
|
||||
recordProcessor: recordProcessor,
|
||||
|
||||
nextCheckpointPair: SequencePair{},
|
||||
|
|
|
|||
Loading…
Reference in a new issue