UNPKG

hypershield

Version:

Middleware suite for high-performance and resilient APIs

41 lines 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CompressionFactory = void 0; const gzipCompressor_1 = require("../../domains/compression/application/gzipCompressor"); class CompressionFactory { static validateOptions(options) { var _a, _b, _c; return { level: Math.min(Math.max((_a = options === null || options === void 0 ? void 0 : options.level) !== null && _a !== void 0 ? _a : 6, 1), 9), chunkSize: (_b = options === null || options === void 0 ? void 0 : options.chunkSize) !== null && _b !== void 0 ? _b : 16 * 1024, memLevel: (_c = options === null || options === void 0 ? void 0 : options.memLevel) !== null && _c !== void 0 ? _c : 8 }; } static createCompressor(type, options) { const key = `${type}-${JSON.stringify(options)}`; if (this.instances.has(key)) { return this.instances.get(key); } const validatedOptions = this.validateOptions(options); let compressor; switch (type) { case 'gzip': compressor = new gzipCompressor_1.GzipCompressor(validatedOptions.level); break; case 'brotli': throw new Error(`Compressor type '${type}' not implemented yet`); case 'deflate': throw new Error(`Compressor type '${type}' not implemented yet`); default: throw new Error(`Compressor type '${type}' not supported`); } this.instances.set(key, compressor); return compressor; } static clearInstances() { this.instances.clear(); } } exports.CompressionFactory = CompressionFactory; CompressionFactory.instances = new Map(); //# sourceMappingURL=compressionFactory.js.map