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

Write after Flush writes 0 bytes, no error because state is closed. #187

Closed
leehinman opened this issue Jun 15, 2022 · 0 comments · Fixed by #188
Closed

Write after Flush writes 0 bytes, no error because state is closed. #187

leehinman opened this issue Jun 15, 2022 · 0 comments · Fixed by #188

Comments

@leehinman
Copy link
Contributor

With this 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())
}

You get:

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]

Notice second write returns 0 for number of bytes written, no error. And data isn't written.

After a Flush, it should be possible to write again, you would just get a new block.

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 a pull request may close this issue.

1 participant