@2501-ai/cli
Version:
[](https://www.npmjs.com/package/@2501-ai/cli) [](https://www.2501.ai/research/full-humaneval-benchmark) [); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.zipUtility = exports.ZipUtility = void 0;
const archiver_1 = __importDefault(require("archiver"));
const fs_1 = require("fs");
const stream_1 = require("stream");
const files_1 = require("./files");
const logger_1 = __importDefault(require("./logger"));
class ZipUtility {
shouldStore(file) {
return (!(0, files_1.isTextFile)(file.path) || file.size > ZipUtility.MEDIUM_FILE_THRESHOLD);
}
createOmittedEntry(relativePath, message) {
return {
content: message,
options: {
name: relativePath,
store: true,
},
};
}
processFileEntry(file, currentTotalSize, options) {
if (options.maxFileSize && file.size > options.maxFileSize) {
return this.createOmittedEntry(file.relativePath, `Content omitted. Reason: File too large. File size: ${(0, files_1.toReadableSize)(file.size)}. Max file size: ${(0, files_1.toReadableSize)(options.maxFileSize)}`);
}
if (options.maxTotalSize &&
currentTotalSize + file.size > options.maxTotalSize) {
return this.createOmittedEntry(file.relativePath, `Content omitted. Reason: Total size would exceed limit. File size: ${(0, files_1.toReadableSize)(file.size)}. Current total: ${(0, files_1.toReadableSize)(currentTotalSize)}. Max total: ${(0, files_1.toReadableSize)(options.maxTotalSize)}`);
}
if (!(0, files_1.isTextFile)(file.path)) {
return this.createOmittedEntry(file.relativePath, 'Content omitted. Reason: Not a text file.');
}
logger_1.default.debug(`Processing ${file.relativePath} with compression level ${this.shouldStore(file) ? 'stored' : 'compressed'} (${(0, files_1.toReadableSize)(file.size)})`);
return {
content: (0, fs_1.createReadStream)(file.path),
options: {
name: file.relativePath,
store: this.shouldStore(file),
},
};
}
createZip(files, options) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
const output = (0, fs_1.createWriteStream)(options.outputPath);
const archive = (0, archiver_1.default)('zip', {
zlib: { level: 6 },
});
let currentTotalSize = 0;
const activeStreams = new Set();
const cleanup = () => {
activeStreams.forEach((stream) => stream.destroy());
activeStreams.clear();
output.destroy();
archive.destroy();
};
output.on('error', (err) => {
cleanup();
reject(err);
});
archive.on('error', (err) => {
cleanup();
reject(err);
});
archive.on('warning', (err) => {
if (err.code === 'ENOENT') {
logger_1.default.warn('ZIP warning:', err);
}
else {
cleanup();
reject(err);
}
});
output.on('close', () => {
logger_1.default.debug(`ZIP created: ${options.outputPath} - ${archive.pointer()} bytes`);
cleanup();
resolve(options.outputPath);
});
archive.pipe(output);
for (const file of files) {
const processed = this.processFileEntry(file, currentTotalSize, options);
if (processed.content instanceof stream_1.Readable) {
activeStreams.add(processed.content);
processed.content.on('end', () => {
activeStreams.delete(processed.content);
});
currentTotalSize += file.size;
}
archive.append(processed.content, processed.options);
}
archive.finalize();
});
});
}
}
exports.ZipUtility = ZipUtility;
ZipUtility.SMALL_FILE_THRESHOLD = 1024 * 1024;
ZipUtility.MEDIUM_FILE_THRESHOLD = 10 * 1024 * 1024;
exports.zipUtility = new ZipUtility();