@opengis/fastify-table
Version:
core-plugins
21 lines (17 loc) • 814 B
JavaScript
import isText from './typeguards/isText.js';
import isPath from './typeguards/isPath.js';
import isBuffer from './typeguards/isBuffer.js';
import isReadableStream from './typeguards/isReadableStream.js';
import isArray from './typeguards/isArray.js';
import sizeHandlers from './handlers/sizeHandlers.js';
const getDataSizeInBytes = async ({ data }) => {
const validators = [isReadableStream, isBuffer, isPath, isText, isArray];
const values = await Promise.all(
validators.map(async (func) => ({ name: func.name, bool: await func(data) })),
);
const [value] = values.filter(({ bool }) => bool === true);
if (!value) throw new Error('No support for this data type');
const handler = sizeHandlers[value.name];
return handler({ data });
};
export default getDataSizeInBytes;