packfs-core
Version:
Semantic filesystem operations for LLM agent frameworks with natural language understanding. See LLM_AGENT_GUIDE.md for copy-paste examples.
50 lines • 1.64 kB
JavaScript
/**
* Base compression strategy interface for PackFS
* Part of the proposed compression system for @yarnpkg/fslib
*/
export class CompressionStrategy {
}
/**
* Registry for compression strategies
*/
export class StrategyRegistry {
constructor() {
this.strategies = new Map();
}
register(strategy) {
this.strategies.set(strategy.name, strategy);
}
get(name) {
return this.strategies.get(name);
}
getOptimal(data, hints) {
const candidates = Array.from(this.strategies.values())
.filter(strategy => strategy.shouldUse(data, hints))
.sort((a, b) => {
// Sort by priority and estimated performance
const aPriority = this.getPriorityScore(a.priority);
const bPriority = this.getPriorityScore(b.priority);
if (hints.isHot) {
// For hot files, prefer speed
return aPriority === 3 ? -1 : bPriority === 3 ? 1 : 0;
}
// For cold files, prefer compression ratio
const aRatio = a.estimateRatio(data, hints);
const bRatio = b.estimateRatio(data, hints);
return bRatio - aRatio;
});
return candidates[0] || this.getDefault();
}
getPriorityScore(priority) {
switch (priority) {
case 'speed': return 3;
case 'balanced': return 2;
case 'size': return 1;
default: return 0;
}
}
getDefault() {
return this.strategies.get('lz4') || Array.from(this.strategies.values())[0];
}
}
//# sourceMappingURL=CompressionStrategy.js.map