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 does this error brotli: RESERVED occur with some data? #45

Open
rew1nter opened this issue Sep 3, 2023 · 2 comments
Open

Why does this error brotli: RESERVED occur with some data? #45

rew1nter opened this issue Sep 3, 2023 · 2 comments

Comments

@rew1nter
Copy link

rew1nter commented Sep 3, 2023

With some data, I'm seeing this error while it works with the rest. What does this error mean and how can I solve it?

This is my code:

// Compress text with the brotli compression algorithm
func Compress(s string) []byte {
	var b bytes.Buffer

	bw := brotli.NewWriter(nil)

	b.Reset()

	// Reset the compressor and encode from some input stream.
	bw.Reset(&b)
	if _, err := io.WriteString(bw, s); err != nil {
		log.Fatal(err)
	}
	if err := bw.Close(); err != nil {
		log.Fatal("failed to comporess:", err)
	}

	return b.Bytes()
}

// Decomporess brotli comporessed data
func Decomporess(data []byte) string {
	b := bytes.NewBuffer(data)
	br := brotli.NewReader(nil)

	// Reset the decompressor and decode to some output stream.
	if err := br.Reset(b); err != nil {
		log.Fatal(err)
	}

	// dst := os.Stdout
	dst := bytes.NewBuffer(nil)
	if _, err := io.Copy(dst, br); err != nil {
		log.Fatal("failed to decomporess:", err)
	}
	return dst.String()
}
@rew1nter
Copy link
Author

rew1nter commented Sep 3, 2023

okay I figured out the error is caused on my end. But still curious when its shown

@andybalholm
Copy link
Owner

In the brotli format, there is a bit in the metablock header that is reserved for future use. It's currently required to be a zero; if there is a one there, it indicates that an incompatible new feature of the format is being used. So an older decoder that doesn't understand the new feature needs to exit with an error. (Note that this new feature is only theoretical; it's not that there actually is a feature that uses that bit yet.)

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

No branches or pull requests

2 participants