Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writer: initialize the writer on Flush() if wasn't initialized before #212

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Empty file added testdata/empty.txt
Empty file.
4 changes: 4 additions & 0 deletions writer.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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