Skip to content

Commit

Permalink
Refactor PaddedReader with FillReader
Browse files Browse the repository at this point in the history
  • Loading branch information
bodgit committed Nov 18, 2022
1 parent 9643ea5 commit 694635d
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions padded.go
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)
}

0 comments on commit 694635d

Please sign in to comment.