Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Forward err also on io.EOF error
Browse files Browse the repository at this point in the history
  • Loading branch information
Juanjo Alvarez committed Sep 21, 2017
1 parent 3f26390 commit 34d47c5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
2 changes: 1 addition & 1 deletion protocol/internal/testnative/native
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
dir=$(dirname $0)
cd $dir
exec go run ./main.go $@
exec go run ./main.go $@
16 changes: 1 addition & 15 deletions protocol/jsonlines/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,11 @@ func NewDecoder(r io.Reader) Decoder {
return &decoder{r: lr}
}

func (d *decoder) readLine() (line []byte, err error) {
line, err = d.r.ReadBytes('\n')

switch(err) {
case nil:
fallthrough
case io.EOF:
return line, nil
default:
// ReadBytes will return all content read until the error
return line, err
}
}

// Decode decodes the next line in the reader.
// It does not check JSON for well-formedness before decoding, so in case of
// error, the structure might be half-filled.
func (d *decoder) Decode(v interface{}) error {
line, err := d.readLine()
line, err := d.r.ReadBytes('\n')
if err != nil {
return err
}
Expand Down
6 changes: 4 additions & 2 deletions protocol/jsonlines/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ func TestDecoder(t *testing.T) {

input := `{"example":1}
{"example":2}
{"example":3}`
{"example":3}
`
d := NewDecoder(strings.NewReader(input))
out := map[string]int{}

Expand All @@ -39,7 +40,8 @@ func TestDecoderWithBufferedReader(t *testing.T) {

input := `{"example":1}
{"example":2}
{"example":3}`
{"example":3}
`
d := NewDecoder(bufio.NewReader(strings.NewReader(input)))
out := map[string]int{}

Expand Down

0 comments on commit 34d47c5

Please sign in to comment.