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

Why the *flate.Writer.Close can not release the reference of passin io.Writer? #219

Closed
bronze1man opened this issue Feb 3, 2020 · 2 comments · Fixed by #224
Closed

Why the *flate.Writer.Close can not release the reference of passin io.Writer? #219

bronze1man opened this issue Feb 3, 2020 · 2 comments · Fixed by #224

Comments

@bronze1man
Copy link

bronze1man commented Feb 3, 2020

If the *flate.Writer.Close release the reference of passin io.Writer, I can simple my code and improve performance a little.
I have tried it, but the test case is failed with

--- FAIL: TestWriterReset (0.09s)
    deflate_test.go:566: got 11274 bytes
    deflate_test.go:566: got 84 bytes
    deflate_test.go:566: got 56 bytes
    deflate_test.go:566: got 4248 bytes
    deflate_test.go:566: got 11274 bytes
    deflate_test.go:566: got 84 bytes
    deflate_test.go:552: got 56, expected 49 bytes
    deflate_test.go:558: mismatch index 2: 31, expected b1
    deflate_test.go:558: mismatch index 5: 20, expected 00
    deflate_test.go:558: mismatch index 6: 00, expected 08
    deflate_test.go:558: mismatch index 7: 04, expected 03
    deflate_test.go:558: mismatch index 8: c0, expected b0
    deflate_test.go:558: mismatch index 9: 2a, expected 6b
    deflate_test.go:562: Stopping

my change code:

func (d *compressor) close() error {
	if d.err != nil {
		return d.err
	}
	d.sync = true
	d.step(d)
	if d.err != nil {
		d.w.writer = nil
		return d.err
	}
	if d.w.writeStoredHeader(0, true); d.w.err != nil {
		d.w.writer = nil
		return d.w.err
	}
	d.w.flush()
	d.w.writer = nil
	return d.w.err
}
@klauspost
Copy link
Owner

Reset also has to reset dictionary state. This deletes it. I will send a PR. Followup shortly.

klauspost added a commit that referenced this issue Feb 16, 2020
Furthermore:

* Clean up dictionary handling & test.
* Fixes dictionary use in levels 1-6.

Fixes #219
@klauspost
Copy link
Owner

See #224 which does what you want and retains the dictionary. Clarified tests as well.

klauspost added a commit that referenced this issue Feb 16, 2020
Furthermore:

* Clean up dictionary handling & test.
* Fixes dictionary use in levels 1-6.

Fixes #219
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.

2 participants