import { coercionInput, checkLevel } from './utils.js';
/** warp module */
export function createModule(options) {
    const { compressSync, compress, decompressSync, decompress, Compressor, Decompressor, TransformStream } = options;
    return {
        compressSync: (data, level) => {
            level = checkLevel(level);
            const input = coercionInput(data, false);
            const output = compressSync(input, level);
            return output;
        },
        compress: async (data, level) => {
            level = checkLevel(level);
            const input = coercionInput(data, true);
            const output = await compress(input, level);
            return output;
        },
        decompressSync: (data) => {
            const input = coercionInput(data, false);
            const output = decompressSync(input);
            return output;
        },
        decompress: async (data) => {
            const input = coercionInput(data, true);
            const output = await decompress(input);
            return output;
        },
        compressor: (level) => {
            level = checkLevel(level);
            const transformer = new TransformStream(new Compressor(level));
            return transformer;
        },
        decompressor: () => {
            const transformer = new TransformStream(new Decompressor());
            return transformer;
        },
    };
}
export const createZSTD_VERSION = (versionNumber) => {
    let _ZSTD_VERSION;
    return () => {
        if (_ZSTD_VERSION)
            return _ZSTD_VERSION;
        // MAJOR * 10000 + MINOR * 100 + PATCH to MAJOR.MINOR.PATCH
        const ZSTD_VERSION_NUMBER = versionNumber();
        const ZSTD_MAJOR = Math.floor(ZSTD_VERSION_NUMBER / 10000);
        const ZSTD_MINOR = Math.floor((ZSTD_VERSION_NUMBER % 10000) / 100);
        const ZSTD_PATCH = ZSTD_VERSION_NUMBER % 100;
        return (_ZSTD_VERSION = `${ZSTD_MAJOR}.${ZSTD_MINOR}.${ZSTD_PATCH}`);
    };
};
//# sourceMappingURL=common.js.map