From 22915133fe0037af3ef31d52c4eedc2ff01bc469 Mon Sep 17 00:00:00 2001 From: Xavi Ramirez Date: Sun, 20 Aug 2017 03:26:32 +0000 Subject: [PATCH] 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. --- kcl/kcl.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/kcl/kcl.go b/kcl/kcl.go index 01d0147..913150e 100644 --- a/kcl/kcl.go +++ b/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{},