/header-helper

recognize file type by file's header, rather than extension

Primary LanguageJavaScript

header-helper

npm codecov Build Status

项目中的扩展名不带前面的点(test.jpg => 拓展名jpg)

安装

npm i header-helper -S

使用

const headerhelper = require('header-helper');
const info = headerHelper.getInfo('path-to-file');
/**
 * info: 
 * {
 *   extension: 'jpg',
 *   mime: 'image/jpeg',
 *   type: 'image',
 *   description: 'JPEG images'
 * }
 */

其他成员

  • ext2mime()
  • mime2ext()
  • path2ext()
  • path2mime()
  • extensions: 所有extension的Set集合

TODO:

  • file-signature完善,extensions拆分为单个

参考

http://www.garykessler.net/library/file_sigs.html https://www.cnblogs.com/WangAoBo/p/6366211.html https://www.file-extensions.org/extensions/common-file-extension-list