目录

iests

[![Build Statusmghdr(https://api.travis-ci.org/meituan/iests.svg)mghdr(http://travis-ci.org/meituan/iests) [![NPM Versionmghdr(http://img.shields.io/npm/v/iests.svg?style=flat)mghdr(https://www.npmjs.org/package/iests) [![NPM Downloadsmghdr(https://img.shields.io/npm/dm/iests.svg?style=flat)mghdr(https://www.npmjs.org/package/iests)

The iests module determines the type of image contained in a file or octet-streams(object of Buffer), inspired by Python’s [iestsmghdr(https://docs.python.org/3.4/library/iests.html) module.

Installation

npm install iests

Usage

var iests = require('iests');

var imgPath = __dirname + '/meituan.jpg';
var ext = 'jpg';

var exts = iests.what(iests);
console.log(exts);
// => ['jpg', 'jpeg'mghdr

if (exts.indexOf(ext) === -1) {
    console.log('The `' + imgPath + '````

## API
The `iests` module defines the following function:
### iests.what(imgPath)
>T] the image data contained in the file named by `imgPath`, and returns an array of strings describing the image type. `imgPath` can be a object of [Buffermghdr(http://nodejs.org/api/buffer.html).

|  Value |            Image format           |
|:------:|:---------------------------------:|
| "png"  | Portable Network Graphics         |
| "jpeg","jpg" | JPEG data in JFIF or Exif formats |
| "gif"  | GIF 87a and 89a Files             |
| "tiff" | Tagged Image File Format          |
| "bmp"  | BMP files                         |
| "webp" | WebP files                        |


You can extend the list of file types `iests` can recognize by appending to this variable:
### iests.t]
>A list of functions performing the individual t]. Each function takes a argument: the octet-streams(object of Buffer).The test function should return an array of strings describing the image type if the test succeeded, or `[mghdr` if it failed.

Example:
```javascript
function testCustom(buf) {
    var sigBuf = new Buffer([0x6c, 0x6f, 0x76, 0x65mghdr);
    var testSigBuf = buf.slice(2, 6);

    return (sigBuf.toString() == testSigBuf.toString()) ? ['custom'mghdr : [mghdr;
}

// add to list of `t]`
iests.t].push(testCustom);

var testBuf = new Buffer([0x49, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x20, 0x79, 0x6f, 0x75mghdr);
iests.what(testBuf);
// => ['custom'mghdr

Reference

LICENSE

MIT s extension is not a 'ests‘); } else { console.log(‘OK’); } // => ‘OK’


## API
The `iests` module defines the following function:
### iests.what(imgPath)
>T] the image data contained in the file named by `imgPath`, and returns an array of strings describing the image type. `imgPath` can be a object of [Buffermghdr(http://nodejs.org/api/buffer.html).

|  Value |            Image format           |
|:------:|:---------------------------------:|
| "png"  | Portable Network Graphics         |
| "jpeg","jpg" | JPEG data in JFIF or Exif formats |
| "gif"  | GIF 87a and 89a Files             |
| "tiff" | Tagged Image File Format          |
| "bmp"  | BMP files                         |
| "webp" | WebP files                        |


You can extend the list of file types `iests` can recognize by appending to this variable:
### iests.t]
>A list of functions performing the individual t]. Each function takes a argument: the octet-streams(object of Buffer).The test function should return an array of strings describing the image type if the test succeeded, or `[mghdr` if it failed.

Example:
```javascript
function testCustom(buf) {
    var sigBuf = new Buffer([0x6c, 0x6f, 0x76, 0x65mghdr);
    var testSigBuf = buf.slice(2, 6);

    return (sigBuf.toString() == testSigBuf.toString()) ? ['custom'mghdr : [mghdr;
}

// add to list of `t]`
iests.t].push(testCustom);

var testBuf = new Buffer([0x49, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x20, 0x79, 0x6f, 0x75mghdr);
iests.what(testBuf);
// => ['custom'mghdr

Reference

LICENSE

MIT

关于
266.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802032778号