-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
options to content writers, including pre-providing the input and out…
…put hashes (#192) Signed-off-by: Avi Deitcher <[email protected]>
- Loading branch information
Showing
7 changed files
with
232 additions
and
85 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
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
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
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package content | ||
|
||
import ( | ||
"github.com/opencontainers/go-digest" | ||
) | ||
|
||
type WriterOpts struct { | ||
InputHash *digest.Digest | ||
OutputHash *digest.Digest | ||
Blocksize int | ||
} | ||
|
||
type WriterOpt func(*WriterOpts) error | ||
|
||
func DefaultWriterOpts() WriterOpts { | ||
return WriterOpts{ | ||
InputHash: nil, | ||
OutputHash: nil, | ||
Blocksize: DefaultBlocksize, | ||
} | ||
} | ||
|
||
// WithInputHash provide the expected input hash to a writer. Writers | ||
// may suppress their own calculation of a hash on the stream, taking this | ||
// hash instead. If the Writer processes the data before passing it on to another | ||
// Writer layer, this is the hash of the *input* stream. | ||
// | ||
// To have a blank hash, use WithInputHash(BlankHash). | ||
func WithInputHash(hash digest.Digest) WriterOpt { | ||
return func(w *WriterOpts) error { | ||
w.InputHash = &hash | ||
return nil | ||
} | ||
} | ||
|
||
// WithOutputHash provide the expected output hash to a writer. Writers | ||
// may suppress their own calculation of a hash on the stream, taking this | ||
// hash instead. If the Writer processes the data before passing it on to another | ||
// Writer layer, this is the hash of the *output* stream. | ||
// | ||
// To have a blank hash, use WithInputHash(BlankHash). | ||
func WithOutputHash(hash digest.Digest) WriterOpt { | ||
return func(w *WriterOpts) error { | ||
w.OutputHash = &hash | ||
return nil | ||
} | ||
} | ||
|
||
// WithBlocksize set the blocksize used by the processor of data. | ||
// The default is DefaultBlocksize, which is the same as that used by io.Copy | ||
func WithBlocksize(blocksize int) WriterOpt { | ||
return func(w *WriterOpts) error { | ||
w.Blocksize = blocksize | ||
return nil | ||
} | ||
} |
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
Oops, something went wrong.