-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor PaddedReader with FillReader
- Loading branch information
Showing
1 changed file
with
1 addition
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
package plumbing | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
) | ||
|
||
// PaddedReader returns an io.Reader that reads at most n bytes from r. If | ||
// fewer than n bytes are available from r then any remaining bytes return | ||
// fill instead. | ||
func PaddedReader(r io.Reader, n int64, fill byte) io.Reader { | ||
// Naive, but works | ||
return io.LimitReader(io.MultiReader(r, bytes.NewBuffer(bytes.Repeat([]byte{fill}, int(n)))), n) | ||
return io.LimitReader(io.MultiReader(r, FillReader(fill)), n) | ||
} |