webpack-bundle-analyzer
Version:
Webpack plugin and CLI utility that represents bundle content as convenient interactive zoomable treemap
19 lines (18 loc) • 706 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getCompressedSize = getCompressedSize;
exports.isZstdSupported = void 0;
const zlib = require('zlib');
const isZstdSupported = exports.isZstdSupported = 'createZstdCompress' in zlib;
function getCompressedSize(compressionAlgorithm, input) {
if (compressionAlgorithm === 'gzip') return zlib.gzipSync(input, {
level: 9
}).length;
if (compressionAlgorithm === 'brotli') return zlib.brotliCompressSync(input).length;
if (compressionAlgorithm === 'zstd' && isZstdSupported) {
return zlib.zstdCompressSync(input).length;
}
throw new Error(`Unsupported compression algorithm: ${compressionAlgorithm}.`);
}