Skip to content

Commit

Permalink
prevent anyone from accidentally setting the blocksize to zero (oras-…
Browse files Browse the repository at this point in the history
…project#197)

Signed-off-by: Avi Deitcher <[email protected]>
  • Loading branch information
deitch authored Nov 10, 2020
1 parent d2037e9 commit f1caa17
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/content/opts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package content

import (
"errors"

"github.com/opencontainers/go-digest"
)

Expand Down Expand Up @@ -47,9 +49,13 @@ func WithOutputHash(hash digest.Digest) WriterOpt {
}

// WithBlocksize set the blocksize used by the processor of data.
// The default is DefaultBlocksize, which is the same as that used by io.Copy
// The default is DefaultBlocksize, which is the same as that used by io.Copy.
// Includes a safety check to ensure the caller doesn't actively set it to <= 0.
func WithBlocksize(blocksize int) WriterOpt {
return func(w *WriterOpts) error {
if blocksize <= 0 {
return errors.New("blocksize must be greater than or equal to 0")
}
w.Blocksize = blocksize
return nil
}
Expand Down

0 comments on commit f1caa17

Please sign in to comment.