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

remove state change after Flush #188

Merged
merged 1 commit into from Jun 15, 2022
Merged

remove state change after Flush #188

merged 1 commit into from Jun 15, 2022

Conversation

leehinman
Copy link
Contributor

A call do Flush does not necessarily mean that the state should change. Another write could come in, if the state is closed this can't occur. Another Write can come in, it just needs to be a new block.

Closes #187

Test Code:

package main

import (
	"bytes"
	"fmt"

	lz4 "github.com/pierrec/lz4/v4"
)

func main() {
	var dst bytes.Buffer

	zw := lz4.NewWriter(&dst)
	n, err := zw.Write([]byte("a"))
	fmt.Printf("First Write: n: %d, err: %v\n", n, err)
	fmt.Printf("dst after first Write(): %v\n", dst.Bytes())
	zw.Flush()
	fmt.Printf("dst after Flush(): %v\n", dst.Bytes())
	n, err = zw.Write([]byte("b"))
	fmt.Printf("Second Write: n: %d, err: %v\n", n, err)
	fmt.Printf("dst after second Write(): %v\n", dst.Bytes())
	zw.Close()
	fmt.Printf("dst after Close(): %v\n", dst.Bytes())
}

Before fix:

First Write: n: 1, err: <nil>
dst after first Write(): [4 34 77 24 100 112 185]
dst after Flush(): [4 34 77 24 100 112 185 1 0 0 128 97]
Second Write: n: 0, err: <nil>
dst after second Write(): [4 34 77 24 100 112 185 1 0 0 128 97]
dst after Close(): [4 34 77 24 100 112 185 1 0 0 128 97 0 0 0 0 86 116 13 85]

After fix:

First Write: n: 1, err: <nil>
dst after first Write(): [4 34 77 24 100 112 185]
dst after Flush(): [4 34 77 24 100 112 185 1 0 0 128 97]
Second Write: n: 1, err: <nil>
dst after second Write(): [4 34 77 24 100 112 185 1 0 0 128 97]
dst after Close(): [4 34 77 24 100 112 185 1 0 0 128 97 1 0 0 128 98 0 0 0 0 83 252 153 73]

A call do Flush does not necessarily mean that the state should
change.  Another write could come in, if the state is closed this
can't occur.  Another Write can come in, it just needs to be a new
block.
@pierrec pierrec merged commit c3eaa1e into pierrec:v4 Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write after Flush writes 0 bytes, no error because state is closed.
2 participants