用于检测是否是icon图片或者是png图片的icojs库。
检测是否是ICON图片
'use strict';
const toDataView = require('to-data-view');
/**
* Check the ArrayBuffer is valid ICO.
*
* @alias module:ICO
* @param {ArrayBuffer|Buffer} source - ICO file data.
* @returns {boolean} True if arg is ICO.
*/
const isICO = source => {
const dataView = toDataView(source);
return dataView.getUint16(0, true) === 0 && dataView.getUint16(2, true) === 1;
};
module.exports = isICO;
检测是否是png图片
'use strict';
const toDataView = require('to-data-view');
/**
* Check the ArrayBuffer is valid PNG.
*
* @access private
* @param {ArrayBuffer|Buffer} source - ArrayBuffer or Buffer object.
* @returns {boolean} Arg is PNG or not.
*/
const isPNG = source => {
const dataView = toDataView(source);
return dataView.getUint32(0, false) === 0x89504E47 && dataView.getUint32(4, false) === 0x0D0A1A0A;
};
module.exports = isPNG;
https://github.com/egy186/icojs