UNPKG

file-type-checker

Version:

Detect and validate file types by their signatures (✨magic numbers✨)

85 lines (84 loc) 3.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isWAV = exports.isMP3 = exports.isM4A = exports.isFLAC = exports.isAMR = exports.isAAC = void 0; const core_1 = require("../core"); const utils_1 = require("../utils"); /** * Determine if file content contains a valid 'aac' file signature * * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array * @param options parameters for additional actions * * @returns {boolean} True if found a signature of type 'aac' in file content, otherwise false */ function isAAC(file, options) { const fileChunk = (0, utils_1.getFileChunk)(file); const iaAac = core_1.FileTypes.checkByFileType(fileChunk, "aac"); if (!iaAac) { if (options === null || options === void 0 ? void 0 : options.excludeSimilarTypes) return false; return isM4A(fileChunk); // since 'm4a' is very similar to 'aac' } return true; } exports.isAAC = isAAC; /** * Determine if file content contains a valid 'amr' file signature * * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array * * @returns {boolean} True if found a signature of type 'amr' in file content, otherwise false */ function isAMR(file) { const fileChunk = (0, utils_1.getFileChunk)(file); return core_1.FileTypes.checkByFileType(fileChunk, "amr"); } exports.isAMR = isAMR; /** * Determine if file content contains a valid 'flac' file signature * * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array * * @returns {boolean} True if found a signature of type 'flac' in file content, otherwise false */ function isFLAC(file) { const fileChunk = (0, utils_1.getFileChunk)(file); return core_1.FileTypes.checkByFileType(fileChunk, "flac"); } exports.isFLAC = isFLAC; /** * Determine if file content contains a valid 'm4a' file signature * * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array * * @returns {boolean} True if found a signature of type 'm4a' in file content, otherwise false */ function isM4A(file) { const fileChunk = (0, utils_1.getFileChunk)(file); return core_1.FileTypes.checkByFileType(fileChunk, "m4a"); } exports.isM4A = isM4A; /** * Determine if file content contains a valid 'mp3' file signature * * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array * * @returns {boolean} True if found a signature of type 'mp3' in file content, otherwise false */ function isMP3(file) { const fileChunk = (0, utils_1.getFileChunk)(file); return core_1.FileTypes.checkByFileType(fileChunk, "mp3"); } exports.isMP3 = isMP3; /** * Determine if file content contains a valid 'wav' file signature * * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array * * @returns {boolean} True if found a signature of type 'wav' in file content, otherwise false */ function isWAV(file) { const fileChunk = (0, utils_1.getFileChunk)(file); return core_1.FileTypes.checkByFileType(fileChunk, "wav"); } exports.isWAV = isWAV;