golang / snappy

The Snappy compression format in the Go programming language.
BSD 3-Clause "New" or "Revised" License
1.52k stars 164 forks source link

Add ReadByte method, satisfies the io.ByteReader interface #51

Closed buth closed 3 years ago

buth commented 4 years ago

Hey all.

In this PR I've added a ReadByte method to Reader in order to implement the io.ByteReader interface. The reasoning is that snappy's reader is already buffered, and needing to wrap it with a bufio.Reader instance in order to, say, directly decode varints leads to extra copying and complication.

I've tried to add as little code as possible, and the only notable change to the code of Reader was to move the buffer-filling loop from the Read method to a bufio-style fill method. The test is a modified version of the test for a buffered Writer, but covers the use case of encoding the length of entries as varints.

Thanks!

googlebot commented 4 years ago

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

buth commented 4 years ago

I did not realize this was a project "owned or managed by Google" (as it's under golang, not google). I'll need to consider the terms of CLA and get back to you.

buth commented 4 years ago

@googlebot I signed it!

googlebot commented 4 years ago

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.