-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #716 from mtrmac/compression-types
Don’t drag in compression implementations into c/image/types
- Loading branch information
Showing
4 changed files
with
88 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package internal | ||
|
||
import "io" | ||
|
||
// CompressorFunc writes the compressed stream to the given writer using the specified compression level. | ||
// The caller must call Close() on the stream (even if the input stream does not need closing!). | ||
type CompressorFunc func(io.Writer, *int) (io.WriteCloser, error) | ||
|
||
// DecompressorFunc returns the decompressed stream, given a compressed stream. | ||
// The caller must call Close() on the decompressed stream (even if the compressed input stream does not need closing!). | ||
type DecompressorFunc func(io.Reader) (io.ReadCloser, error) | ||
|
||
// Algorithm is a compression algorithm that can be used for CompressStream. | ||
type Algorithm struct { | ||
name string | ||
prefix []byte | ||
decompressor DecompressorFunc | ||
compressor CompressorFunc | ||
} | ||
|
||
// NewAlgorithm creates an Algorithm instance. | ||
// This function exists so that Algorithm instances can only be created by code that | ||
// is allowed to import this internal subpackage. | ||
func NewAlgorithm(name string, prefix []byte, decompressor DecompressorFunc, compressor CompressorFunc) Algorithm { | ||
return Algorithm{ | ||
name: name, | ||
prefix: prefix, | ||
decompressor: decompressor, | ||
compressor: compressor, | ||
} | ||
} | ||
|
||
// Name returns the name for the compression algorithm. | ||
func (c Algorithm) Name() string { | ||
return c.name | ||
} | ||
|
||
// AlgorithmCompressor returns the compressor field of algo. | ||
// This is a function instead of a public method so that it is only callable from by code | ||
// that is allowed to import this internal subpackage. | ||
func AlgorithmCompressor(algo Algorithm) CompressorFunc { | ||
return algo.compressor | ||
} | ||
|
||
// AlgorithmDecompressor returns the decompressor field of algo. | ||
// This is a function instead of a public method so that it is only callable from by code | ||
// that is allowed to import this internal subpackage. | ||
func AlgorithmDecompressor(algo Algorithm) DecompressorFunc { | ||
return algo.decompressor | ||
} | ||
|
||
// AlgorithmPrefix returns the prefix field of algo. | ||
// This is a function instead of a public method so that it is only callable from by code | ||
// that is allowed to import this internal subpackage. | ||
func AlgorithmPrefix(algo Algorithm) []byte { | ||
return algo.prefix | ||
} |
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,13 @@ | ||
package types | ||
|
||
import ( | ||
"github.com/containers/image/pkg/compression/internal" | ||
) | ||
|
||
// DecompressorFunc returns the decompressed stream, given a compressed stream. | ||
// The caller must call Close() on the decompressed stream (even if the compressed input stream does not need closing!). | ||
type DecompressorFunc = internal.DecompressorFunc | ||
|
||
// Algorithm is a compression algorithm provided and supported by pkg/compression. | ||
// It can’t be supplied from the outside. | ||
type Algorithm = internal.Algorithm |
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