* 嗅探文件格式 * @param filePath 文件路径 * @returns 匹配的格式特征,如果无法识别则返回 null
(filePath: string)
| 86 | * @returns 匹配的格式特征,如果无法识别则返回 null |
| 87 | */ |
| 88 | sniff(filePath: string): FormatFeature | null { |
| 89 | const ext = getExtension(filePath) |
| 90 | const headContent = readFileHead(filePath) |
| 91 | |
| 92 | for (const { feature } of this.formats) { |
| 93 | if (this.matchFeature(feature, ext, headContent, filePath)) { |
| 94 | return feature |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | return null |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * 获取文件对应的解析器 |
no test coverage detected