UNPKG

file-streamer

Version:

A TypeScript package for streaming data as files (Excel, CSV, JSON, Base64) and streaming files from file system through HTTP responses

63 lines 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getFileExtensionFromMimeType = exports.getContentTypeFromExtension = void 0; const extensionToMimeType = { '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.gif': 'image/gif', '.webp': 'image/webp', '.svg': 'image/svg+xml', '.pdf': 'application/pdf', '.txt': 'text/plain', '.html': 'text/html', '.css': 'text/css', '.js': 'text/javascript', '.json': 'application/json', '.xml': 'application/xml', '.zip': 'application/zip', '.doc': 'application/msword', '.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', '.xls': 'application/vnd.ms-excel', '.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', '.mp4': 'video/mp4', '.webm': 'video/webm', '.mp3': 'audio/mpeg', '.wav': 'audio/wav', '.ogg': 'audio/ogg' }; const mimeTypeToExtension = { 'image/png': '.png', 'image/jpeg': '.jpg', 'image/jpg': '.jpg', 'image/gif': '.gif', 'image/webp': '.webp', 'image/svg+xml': '.svg', 'application/pdf': '.pdf', 'text/plain': '.txt', 'text/html': '.html', 'text/css': '.css', 'text/javascript': '.js', 'application/json': '.json', 'application/xml': '.xml', 'application/zip': '.zip', 'application/x-zip-compressed': '.zip', 'application/msword': '.doc', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': '.docx', 'application/vnd.ms-excel': '.xls', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': '.xlsx', 'video/mp4': '.mp4', 'video/webm': '.webm', 'audio/mpeg': '.mp3', 'audio/wav': '.wav', 'audio/ogg': '.ogg' }; const getContentTypeFromExtension = (extension) => { return extensionToMimeType[extension.toLowerCase()] || 'application/octet-stream'; }; exports.getContentTypeFromExtension = getContentTypeFromExtension; const getFileExtensionFromMimeType = (mimeType) => { return mimeTypeToExtension[mimeType.toLowerCase()] || '.bin'; }; exports.getFileExtensionFromMimeType = getFileExtensionFromMimeType; //# sourceMappingURL=mime-types.js.map