Documentation
¶
Overview ¶
Package reversible provides compression implementations.
Package reversible provides pipeline integration for reversible compression.
Package reversible provides SQLite-backed storage for compressed entries.
Package reversible implements Claw Compactor's Rewind engine for reversible compression.
Index ¶
- func ComputeHash(content string) string
- func ComputeShortHash(content string) string
- func InjectMarker(text string, marker Marker, maxLen int) string
- type AESEncryptor
- type CLI
- func (c *CLI) ClearCommand(olderThan time.Duration) (int64, error)
- func (c *CLI) ListCommand(filter ListFilter) ([]*Entry, error)
- func (c *CLI) RetrieveCommand(hash string) (*Entry, error)
- func (c *CLI) StatsCommand() (StoreStats, error)
- func (c *CLI) StoreCommand(content string, command string) (string, error)
- func (c *CLI) VacuumCommand() error
- type ClassificationResult
- type Classifier
- type CommandRecord
- type Compressor
- type Config
- type ContentType
- type Encryptor
- type Entry
- type Integration
- type LZ4Compressor
- type ListFilter
- type Marker
- type NoOpCompressor
- type Pipeline
- type SQLiteStore
- func (s *SQLiteStore) Close() error
- func (s *SQLiteStore) Delete(hash string) error
- func (s *SQLiteStore) DeleteOlderThan(d time.Duration) (int64, error)
- func (s *SQLiteStore) GetCommandHistory(limit int) ([]*CommandRecord, error)
- func (s *SQLiteStore) List(filter ListFilter) ([]*Entry, error)
- func (s *SQLiteStore) RecordCommand(record *CommandRecord) error
- func (s *SQLiteStore) Retrieve(hash string) (*Entry, error)
- func (s *SQLiteStore) Save(entry *Entry) (string, error)
- func (s *SQLiteStore) Stats() (StoreStats, error)
- func (s *SQLiteStore) Vacuum() error
- type SimpleClassifier
- type Store
- type StoreStats
- type StreamingReader
- type ZstdCompressor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComputeHash ¶
ComputeHash computes the full SHA-256 hash.
func ComputeShortHash ¶
ComputeShortHash computes the 16-char short hash for markers.
Types ¶
type AESEncryptor ¶
type AESEncryptor struct {
// contains filtered or unexported fields
}
AESEncryptor implements AES-256-GCM encryption.
func NewAESEncryptor ¶
func NewAESEncryptor(key []byte) (*AESEncryptor, error)
NewAESEncryptor creates a new AES encryptor.
type CLI ¶
type CLI struct {
// contains filtered or unexported fields
}
CLI provides command-line interface for reversible compression.
func (*CLI) ClearCommand ¶
ClearCommand handles the `rewind clear` command.
func (*CLI) ListCommand ¶
func (c *CLI) ListCommand(filter ListFilter) ([]*Entry, error)
ListCommand handles the `rewind list` command.
func (*CLI) RetrieveCommand ¶
RetrieveCommand handles the `rewind retrieve` command.
func (*CLI) StatsCommand ¶
func (c *CLI) StatsCommand() (StoreStats, error)
StatsCommand handles the `rewind stats` command.
func (*CLI) StoreCommand ¶
StoreCommand handles the `rewind store` command.
func (*CLI) VacuumCommand ¶
VacuumCommand handles the `rewind vacuum` command.
type ClassificationResult ¶
type ClassificationResult struct {
Type ContentType
Confidence float64
Language string
}
ClassificationResult contains content classification info.
type Classifier ¶
type Classifier interface {
// Classify determines the content type.
Classify(content string) ClassificationResult
}
Classifier provides content classification.
type CommandRecord ¶
type CommandRecord struct {
Command string `json:"command"`
Hash string `json:"hash"`
Timestamp time.Time `json:"timestamp"`
Duration time.Duration `json:"duration"`
Compressed bool `json:"compressed"`
}
CommandRecord stores command execution history.
type Compressor ¶
type Compressor interface {
// Compress compresses data and returns the compressed bytes.
Compress(data []byte) ([]byte, error)
// Decompress decompresses data.
Decompress(data []byte) ([]byte, error)
// Name returns the compressor name.
Name() string
}
Compressor provides compression functionality.
type Config ¶
type Config struct {
// StorePath is the path to the SQLite database.
StorePath string
// EncryptionKey is the AES-256-GCM key (nil for no encryption).
EncryptionKey []byte
// DefaultAlgorithm is the default compression algorithm.
DefaultAlgorithm string // "zstd", "lz4", "none"
// MaxEntrySize is the maximum size for a single entry (default 100MB).
MaxEntrySize int64
// AutoVacuum enables automatic vacuum after deletes.
AutoVacuum bool
}
Config provides configuration for the reversible compression system.
type ContentType ¶
type ContentType int
ContentType represents the classification of content for compression.
const ( TypeLossless ContentType = iota // No loss acceptable (code, config) TypeLossy // Minor loss OK (logs with timestamps) TypeSemantic // Semantic preservation only (docs) )
type Encryptor ¶
type Encryptor interface {
// Encrypt encrypts data with the given key.
Encrypt(plaintext []byte) ([]byte, error)
// Decrypt decrypts data with the given key.
Decrypt(ciphertext []byte) ([]byte, error)
}
Encryptor provides encryption functionality.
type Entry ¶
type Entry struct {
Hash string `json:"hash"`
Original string `json:"original"`
Compressed string `json:"compressed,omitempty"` // Not stored if encrypted
Command string `json:"command,omitempty"`
ContentType ContentType `json:"content_type"`
CompressionAlg string `json:"compression_alg"` // "zstd", "lz4", "none"
Encrypted bool `json:"encrypted"`
CreatedAt time.Time `json:"created_at"`
AccessedAt time.Time `json:"accessed_at"`
AccessCount int `json:"access_count"`
SizeOriginal int64 `json:"size_original"`
SizeCompressed int64 `json:"size_compressed"`
// These fields are only populated when retrieving, not stored in DB
CompressedData []byte `json:"-"` // Raw compressed bytes (encrypted if Encrypted=true)
}
Entry represents a stored compressed entry.
func (*Entry) CompressionRatio ¶
CompressionRatio returns the compression ratio.
func (*Entry) SavedPercentage ¶
SavedPercentage returns percentage of space saved.
type Integration ¶
type Integration struct {
// contains filtered or unexported fields
}
Integration provides integration with TokMan's existing filter pipeline.
func NewIntegration ¶
func NewIntegration(store Store, config Config) *Integration
NewIntegration creates a new pipeline integration.
func SetupDefault ¶
func SetupDefault() (*Integration, error)
SetupDefault creates a default integration with SQLite store.
func (*Integration) IsEnabled ¶
func (i *Integration) IsEnabled() bool
IsEnabled returns true if integration is enabled.
func (*Integration) ProcessFilterOutput ¶
func (i *Integration) ProcessFilterOutput(original, compressed string, command string) (string, error)
ProcessFilterOutput processes output from the filter pipeline.
func (*Integration) RestoreInput ¶
func (i *Integration) RestoreInput(input string) (string, error)
RestoreInput restores original content from input containing markers.
type LZ4Compressor ¶
type LZ4Compressor struct {
}
LZ4Compressor implements lz4 compression.
func (*LZ4Compressor) Compress ¶
func (l *LZ4Compressor) Compress(data []byte) ([]byte, error)
Compress implements Compressor.
func (*LZ4Compressor) Decompress ¶
func (l *LZ4Compressor) Decompress(data []byte) ([]byte, error)
Decompress implements Compressor.
func (*LZ4Compressor) Name ¶
func (l *LZ4Compressor) Name() string
Name returns the compressor name.
type ListFilter ¶
type ListFilter struct {
Command string
ContentType ContentType
Since time.Time
Before time.Time
MinSize int64
MaxSize int64
Limit int
}
ListFilter provides filtering for List operations.
type Marker ¶
type Marker struct {
Hash string // First 16 chars of SHA-256
FullHash string // Full 64-char hash for verification
}
Marker represents a hash marker for referencing compressed content.
func ExtractMarkers ¶
ExtractMarkers extracts all markers from text.
func ParseMarker ¶
ParseMarker parses a marker string in [rewind:hash16] format.
type NoOpCompressor ¶
type NoOpCompressor struct{}
NoOpCompressor implements no compression (pass-through).
func (*NoOpCompressor) Compress ¶
func (n *NoOpCompressor) Compress(data []byte) ([]byte, error)
Compress implements Compressor.
func (*NoOpCompressor) Decompress ¶
func (n *NoOpCompressor) Decompress(data []byte) ([]byte, error)
Decompress implements Compressor.
func (*NoOpCompressor) Name ¶
func (n *NoOpCompressor) Name() string
Name returns the compressor name.
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline integrates reversible compression with command execution.
func NewPipeline ¶
NewPipeline creates a new reversible compression pipeline.
func (*Pipeline) ProcessOutput ¶
ProcessOutput processes output text and replaces markers with original content.
type SQLiteStore ¶
type SQLiteStore struct {
// contains filtered or unexported fields
}
SQLiteStore implements Store using SQLite.
func NewSQLiteStore ¶
func NewSQLiteStore(config Config) (*SQLiteStore, error)
NewSQLiteStore creates a new SQLite-backed store.
func (*SQLiteStore) Delete ¶
func (s *SQLiteStore) Delete(hash string) error
Delete removes an entry.
func (*SQLiteStore) DeleteOlderThan ¶
func (s *SQLiteStore) DeleteOlderThan(d time.Duration) (int64, error)
DeleteOlderThan deletes entries older than duration.
func (*SQLiteStore) GetCommandHistory ¶
func (s *SQLiteStore) GetCommandHistory(limit int) ([]*CommandRecord, error)
GetCommandHistory returns command history.
func (*SQLiteStore) List ¶
func (s *SQLiteStore) List(filter ListFilter) ([]*Entry, error)
List returns entries matching the filter.
func (*SQLiteStore) RecordCommand ¶
func (s *SQLiteStore) RecordCommand(record *CommandRecord) error
RecordCommand records command execution.
func (*SQLiteStore) Retrieve ¶
func (s *SQLiteStore) Retrieve(hash string) (*Entry, error)
Retrieve gets an entry by hash (short or full).
func (*SQLiteStore) Save ¶
func (s *SQLiteStore) Save(entry *Entry) (string, error)
Save stores an entry and returns its hash.
func (*SQLiteStore) Stats ¶
func (s *SQLiteStore) Stats() (StoreStats, error)
Stats returns store statistics.
type SimpleClassifier ¶
type SimpleClassifier struct{}
SimpleClassifier implements basic content classification.
func (*SimpleClassifier) Classify ¶
func (c *SimpleClassifier) Classify(content string) ClassificationResult
Classify implements Classifier.
type Store ¶
type Store interface {
// Save stores an entry and returns its hash.
Save(entry *Entry) (string, error)
// Retrieve gets an entry by hash (short or full).
Retrieve(hash string) (*Entry, error)
// Delete removes an entry.
Delete(hash string) error
// List returns all entries, optionally filtered.
List(filter ListFilter) ([]*Entry, error)
// Stats returns store statistics.
Stats() (StoreStats, error)
// Vacuum reclaims space.
Vacuum() error
}
Store provides persistent storage for reversible compression.
type StoreStats ¶
type StoreStats struct {
TotalEntries int64
TotalSizeOrig int64
TotalSizeComp int64
OldestEntry time.Time
NewestEntry time.Time
ByContentType map[ContentType]int64
ByCommand map[string]int64
}
StoreStats provides statistics about the store.
type StreamingReader ¶
type StreamingReader interface {
// Read reads decompressed data.
Read(p []byte) (n int, err error)
// Close closes the reader.
Close() error
}
StreamingReader provides streaming decompression.
type ZstdCompressor ¶
type ZstdCompressor struct {
// contains filtered or unexported fields
}
ZstdCompressor implements zstd compression.
func (*ZstdCompressor) Compress ¶
func (z *ZstdCompressor) Compress(data []byte) ([]byte, error)
Compress implements Compressor.
func (*ZstdCompressor) Decompress ¶
func (z *ZstdCompressor) Decompress(data []byte) ([]byte, error)
Decompress implements Compressor.
func (*ZstdCompressor) Name ¶
func (z *ZstdCompressor) Name() string
Name returns the compressor name.