Skip to content

Commit

Permalink
Merge pull request #212 from edigaryev/writer-init-on-flush
Browse files Browse the repository at this point in the history
Writer: initialize the writer on Flush() if wasn't initialized before
  • Loading branch information
pierrec committed Dec 7, 2023
2 parents ef495ee + 3ac62b5 commit a0f6c5e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
Empty file added testdata/empty.txt
Empty file.
4 changes: 4 additions & 0 deletions writer.go
Expand Up @@ -150,6 +150,10 @@ func (w *Writer) Flush() (err error) {
case writeState:
case errorState:
return w.state.err
case newState:
if err = w.init(); w.state.next(err) {
return
}
default:
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion writer_test.go
Expand Up @@ -17,6 +17,7 @@ import (

func TestWriter(t *testing.T) {
goldenFiles := []string{
"testdata/empty.txt",
"testdata/e.txt",
"testdata/gettysburg.txt",
"testdata/Mark.Twain-Tom.Sawyer.txt",
Expand Down Expand Up @@ -75,7 +76,7 @@ func TestWriter(t *testing.T) {
t.Errorf("invalid sizes: got %d; want %d", got, want)
}

if got, want := out.Bytes(), raw; !reflect.DeepEqual(got, want) {
if got, want := out.Bytes(), raw; !bytes.Equal(got, want) {
t.Fatal("uncompressed data does not match original")
}

Expand Down

0 comments on commit a0f6c5e

Please sign in to comment.