Documentation
¶
Overview ¶
Package compression provides advanced compression algorithms for CargoShip
Package compression provides content-aware compression optimization (Issue #105)
Index ¶
- func EstimateCompressionBenefit(contentType ContentType) float64
- func ShouldCompress(contentType ContentType) bool
- type Algorithm
- type CompressionResult
- type CompressionStrategy
- type Compressor
- type ContentAwareCompressor
- func (cac *ContentAwareCompressor) GetCompressionStrategy(filename string) CompressionStrategy
- func (cac *ContentAwareCompressor) GetOptimalSettings(filename string) (Algorithm, Level)
- func (cac *ContentAwareCompressor) GetOptimalSettingsWithMetadata(filename string, metadata map[string]string) (Algorithm, Level)
- func (cac *ContentAwareCompressor) GetSettingsForContentType(contentType ContentType) (Algorithm, Level)
- type ContentAwareConfig
- type ContentType
- type Level
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EstimateCompressionBenefit ¶ added in v0.6.1
func EstimateCompressionBenefit(contentType ContentType) float64
EstimateCompressionBenefit estimates compression benefit for a content type Returns a score from 0.0 (no benefit) to 1.0 (maximum benefit)
func ShouldCompress ¶ added in v0.6.1
func ShouldCompress(contentType ContentType) bool
ShouldCompress determines if a file should be compressed based on content type
Types ¶
type Algorithm ¶
type Algorithm string
Algorithm represents a compression algorithm
func GetSupportedAlgorithms ¶
func GetSupportedAlgorithms() []Algorithm
GetSupportedAlgorithms returns a list of supported compression algorithms
func RecommendAlgorithm ¶
RecommendAlgorithm recommends the best compression algorithm based on data characteristics
type CompressionResult ¶
type CompressionResult struct {
Algorithm Algorithm `json:"algorithm"`
Level Level `json:"level"`
OriginalSize int64 `json:"original_size"`
CompressedSize int64 `json:"compressed_size"`
CompressionRatio float64 `json:"compression_ratio"`
CompressionTime int64 `json:"compression_time_ms"`
Throughput float64 `json:"throughput_mbps"`
}
CompressionResult contains compression statistics
func BenchmarkCompression ¶
func BenchmarkCompression(data io.Reader, dataSize int64) ([]CompressionResult, error)
BenchmarkCompression benchmarks different compression algorithms on sample data
type CompressionStrategy ¶ added in v0.6.1
type CompressionStrategy struct {
ContentType ContentType
Algorithm Algorithm
Level Level
Benefit float64 // Estimated compression benefit (0.0-1.0)
ShouldSkip bool // Whether to skip compression entirely
}
CompressionStrategy describes a compression strategy for a content type
type Compressor ¶
type Compressor struct {
// contains filtered or unexported fields
}
Compressor provides compression and decompression functionality
func NewCompressor ¶
func NewCompressor(algorithm Algorithm, level Level) (*Compressor, error)
NewCompressor creates a new compressor with the specified algorithm and level
func (*Compressor) Compress ¶
func (c *Compressor) Compress(data io.Reader) (io.Reader, *CompressionResult, error)
Compress compresses data using the configured algorithm
func (*Compressor) Decompress ¶
Decompress decompresses data using the configured algorithm
type ContentAwareCompressor ¶ added in v0.6.1
type ContentAwareCompressor struct {
// contains filtered or unexported fields
}
ContentAwareCompressor provides content-aware compression optimization
func NewContentAwareCompressor ¶ added in v0.6.1
func NewContentAwareCompressor(config *ContentAwareConfig) *ContentAwareCompressor
NewContentAwareCompressor creates a new content-aware compressor
func (*ContentAwareCompressor) GetCompressionStrategy ¶ added in v0.6.1
func (cac *ContentAwareCompressor) GetCompressionStrategy(filename string) CompressionStrategy
GetCompressionStrategy returns a complete compression strategy for a file
func (*ContentAwareCompressor) GetOptimalSettings ¶ added in v0.6.1
func (cac *ContentAwareCompressor) GetOptimalSettings(filename string) (Algorithm, Level)
GetOptimalSettings returns the optimal compression algorithm and level for a file
func (*ContentAwareCompressor) GetOptimalSettingsWithMetadata ¶ added in v0.7.3
func (cac *ContentAwareCompressor) GetOptimalSettingsWithMetadata( filename string, metadata map[string]string, ) (Algorithm, Level)
GetOptimalSettingsWithMetadata returns optimal compression with Magika metadata support (Issue #30)
func (*ContentAwareCompressor) GetSettingsForContentType ¶ added in v0.6.1
func (cac *ContentAwareCompressor) GetSettingsForContentType(contentType ContentType) (Algorithm, Level)
GetSettingsForContentType returns compression settings for a content type
type ContentAwareConfig ¶ added in v0.6.1
type ContentAwareConfig struct {
// Per-content-type compression levels
ImageLevel Level `yaml:"image_level" json:"image_level"` // Images (already compressed)
VideoLevel Level `yaml:"video_level" json:"video_level"` // Video (already compressed)
AudioLevel Level `yaml:"audio_level" json:"audio_level"` // Audio (already compressed)
DocumentLevel Level `yaml:"document_level" json:"document_level"` // Documents (good compression)
CodeLevel Level `yaml:"code_level" json:"code_level"` // Source code (best compression)
BinaryLevel Level `yaml:"binary_level" json:"binary_level"` // Binary executables (fast)
TextLevel Level `yaml:"text_level" json:"text_level"` // Plain text (good compression)
ArchiveLevel Level `yaml:"archive_level" json:"archive_level"` // Archives (minimal)
DefaultLevel Level `yaml:"default_level" json:"default_level"` // Unknown types
// Algorithm selection per content type
ImageAlgorithm Algorithm `yaml:"image_algorithm" json:"image_algorithm"`
VideoAlgorithm Algorithm `yaml:"video_algorithm" json:"video_algorithm"`
AudioAlgorithm Algorithm `yaml:"audio_algorithm" json:"audio_algorithm"`
DocumentAlgorithm Algorithm `yaml:"document_algorithm" json:"document_algorithm"`
CodeAlgorithm Algorithm `yaml:"code_algorithm" json:"code_algorithm"`
BinaryAlgorithm Algorithm `yaml:"binary_algorithm" json:"binary_algorithm"`
TextAlgorithm Algorithm `yaml:"text_algorithm" json:"text_algorithm"`
ArchiveAlgorithm Algorithm `yaml:"archive_algorithm" json:"archive_algorithm"`
DefaultAlgorithm Algorithm `yaml:"default_algorithm" json:"default_algorithm"`
}
ContentAwareConfig configures content-aware compression per content type
func DefaultContentAwareConfig ¶ added in v0.6.1
func DefaultContentAwareConfig() *ContentAwareConfig
DefaultContentAwareConfig returns optimized defaults for content-aware compression
type ContentType ¶ added in v0.6.1
type ContentType string
ContentType represents different content categories for compression
const ( ContentTypeImage ContentType = "image" ContentTypeVideo ContentType = "video" ContentTypeAudio ContentType = "audio" ContentTypeDocument ContentType = "document" ContentTypeCode ContentType = "code" ContentTypeBinary ContentType = "binary" ContentTypeText ContentType = "text" ContentTypeArchive ContentType = "archive" ContentTypeUnknown ContentType = "unknown" )
func DetectContentType ¶ added in v0.6.1
func DetectContentType(filename string) ContentType
DetectContentType detects the content type from filename/extension
func DetectContentTypeWithMetadata ¶ added in v0.7.3
func DetectContentTypeWithMetadata(filename string, metadata map[string]string) ContentType
DetectContentTypeWithMetadata detects content type using Magika metadata if available, falling back to extension-based detection (Issue #30)