buffer-type
Advanced tools
Comparing version 0.0.1 to 0.0.2
0.0.2 / 2014-05-04 | ||
================== | ||
* add webp detect | ||
0.0.1 / 2013-08-13 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -1,8 +0,12 @@ | ||
/*! | ||
/**! | ||
* buffer-type - lib/buffer-type.js | ||
* Copyright(c) 2013 fengmk2 <fengmk2@gmail.com> | ||
* | ||
* Copyright(c) fengmk2 and other contributors. | ||
* MIT Licensed | ||
* | ||
* Authors: | ||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com) | ||
*/ | ||
"use strict"; | ||
'use strict'; | ||
@@ -15,3 +19,3 @@ /** | ||
* @see http://www.onicos.com/staff/iz/formats/gif.html | ||
* | ||
* | ||
GIF format | ||
@@ -36,3 +40,3 @@ | ||
1 bytes <Trailer> (0x3b) | ||
* | ||
* | ||
*/ | ||
@@ -43,3 +47,3 @@ var gif = function (buf) { | ||
buf[0] !== 0x47 || buf[1] !== 0x49 || buf[2] !== 0x46 || | ||
// "87a" or "89a" | ||
// "87a" or "89a" | ||
buf[3] !== 0x38 || (buf[4] !== 0x39 && buf[4] !== 0x37) || buf[5] !== 0x61) { | ||
@@ -68,3 +72,3 @@ return; | ||
0A A Unix-style line ending (LF) to detect Unix-DOS line ending conversion. | ||
* | ||
* | ||
*/ | ||
@@ -112,3 +116,3 @@ var png = function (buf) { | ||
* @see http://blog.csdn.net/lpt19832003/article/details/1713718 | ||
* | ||
* | ||
JPEG format | ||
@@ -139,3 +143,3 @@ | ||
1 byte 0xd9 (EOI) end-of-file | ||
* | ||
* | ||
*/ | ||
@@ -145,3 +149,3 @@ | ||
if (buf.length < 20 || | ||
// 0xff 0xd8(SOI) | ||
// 0xff 0xd8(SOI) | ||
buf[0] !== 0xff || buf[1] !== 0xd8 || | ||
@@ -165,3 +169,3 @@ // 0xff 0xe0(APP0) | ||
// var height = buf.readUInt16BE(16, true); | ||
// DQT,Define Quantization Table,定义量化表 | ||
@@ -179,3 +183,3 @@ // * 标记代码 2字节 固定值0xFFDB | ||
// 本标记段中,字段②可以重复出现,表示多个量化表,但最多只能出现4次。 | ||
// SOF0,Start of Frame,帧图像开始 | ||
@@ -194,3 +198,3 @@ // u 标记代码 2字节 固定值0xFFC0 | ||
// ⑥颜色分量信息 颜色分量数×3字节(通常为9字节) | ||
// a) 颜色分量ID 1字节 | ||
// a) 颜色分量ID 1字节 | ||
// b) 水平/垂直采样因子 1字节 高4位:水平采样因子 | ||
@@ -202,3 +206,3 @@ // 低4位:垂直采样因子 | ||
// 本标记段中,字段⑥应该重复出现,有多少个颜色分量(字段⑤),就出现多少次(一般为3次)。 | ||
// find SOF0 | ||
@@ -268,3 +272,3 @@ var offset = 20; | ||
54 (n-40) bytes OS/2 new extentional fields?? | ||
* | ||
* | ||
*/ | ||
@@ -295,4 +299,43 @@ | ||
var types = [gif, png, jpeg, bmp]; | ||
// webp format: https://developers.google.com/speed/webp/docs/riff_container | ||
// WebP File Header | ||
// 0 1 2 3 | ||
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
// | 'R' | 'I' | 'F' | 'F' | | ||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
// | File Size | | ||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
// | 'W' | 'E' | 'B' | 'P' | | ||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
// | ||
// 'RIFF': 32 bits | ||
// The ASCII characters 'R' 'I' 'F' 'F'. | ||
// File Size: 32 bits (uint32) | ||
// The size of the file in bytes starting at offset 8. | ||
// The maximum value of this field is 2^32 minus 10 bytes and | ||
// thus the size of the whole file is at most 4GiB minus 2 bytes. | ||
// 'WEBP': 32 bits | ||
// The ASCII characters 'W' 'E' 'B' 'P'. | ||
function webp(buf) { | ||
if (buf.length < 12) { | ||
return; | ||
} | ||
if (buf.slice(0, 4).toString() !== 'RIFF' || buf.slice(8, 12).toString() !== 'WEBP') { | ||
return; | ||
} | ||
// uint32: A 32-bit, little-endian, unsigned integer. | ||
// The file size in the header is the total size of the chunks that follow plus 4 bytes for the 'WEBP' FourCC. | ||
var size = buf.readUInt32LE(4); | ||
return { | ||
type: 'image/webp', | ||
extension: '.webp', | ||
size: size + 8 | ||
}; | ||
} | ||
var types = [gif, png, jpeg, bmp, webp]; | ||
function detect(buf) { | ||
@@ -302,3 +345,3 @@ if (!buf || !buf.length) { | ||
} | ||
for (var i = 0; i < types.length; i++) { | ||
@@ -305,0 +348,0 @@ var r = types[i](buf); |
{ | ||
"name": "buffer-type", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Detect content-type from Buffer data.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "make test-all", | ||
"blanket": { | ||
"test": "make test-all" | ||
}, | ||
"config": { | ||
"blanket": { | ||
"pattern": "buffer-type/lib", | ||
@@ -30,9 +32,14 @@ "data-cover-flags": { | ||
}, | ||
"homepage": "https://github.com/node-modules/buffer-type", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/fengmk2/buffer-type.git", | ||
"web": "https://github.com/fengmk2/buffer-type" | ||
"url": "git://github.com/node-modules/buffer-type.git", | ||
"web": "https://github.com/node-modules/buffer-type" | ||
}, | ||
"keywords": [ | ||
"buffer-type", "content-type", "buffer", "type", "filetype", "file extension", "buffer type" | ||
"buffer-type", | ||
"image-type", | ||
"content-type", "buffer", "type", | ||
"mime", | ||
"filetype", "file extension", "buffer type" | ||
], | ||
@@ -39,0 +46,0 @@ "engines": { |
buffer-type | ||
======= | ||
[![Build Status](https://secure.travis-ci.org/fengmk2/buffer-type.png)](http://travis-ci.org/fengmk2/buffer-type) [![Coverage Status](https://coveralls.io/repos/fengmk2/buffer-type/badge.png)](https://coveralls.io/r/fengmk2/buffer-type) [![Build Status](https://drone.io/github.com/fengmk2/buffer-type/status.png)](https://drone.io/github.com/fengmk2/buffer-type/latest) | ||
[![Build Status](https://secure.travis-ci.org/node-modules/buffer-type.png)](http://travis-ci.org/node-modules/buffer-type) | ||
![logo](https://raw.github.com/fengmk2/buffer-type/master/logo.png) | ||
[![Coverage Status](https://coveralls.io/repos/node-modules/buffer-type/badge.png)](https://coveralls.io/r/node-modules/buffer-type) | ||
[![NPM](https://nodei.co/npm/buffer-type.png?downloads=true&stars=true)](https://nodei.co/npm/buffer-type/) | ||
![logo](https://raw.github.com/node-modules/buffer-type/master/logo.png) | ||
Detect content-type from Buffer data. | ||
@@ -51,2 +55,6 @@ | ||
* [√] .gif | ||
* [√] .webp | ||
* [ ] .svg | ||
* [ ] .tif | ||
* [ ] .psd | ||
* Tar | ||
@@ -65,2 +73,3 @@ * [ ] .tar | ||
* [ ] .html | ||
* [ ] .json | ||
* Media | ||
@@ -74,3 +83,3 @@ * [ ] .mp3 | ||
```bash | ||
$ git summary | ||
$ git summary | ||
@@ -82,7 +91,7 @@ project : buffer-type | ||
files : 17 | ||
authors : | ||
authors : | ||
5 fengmk2 100.0% | ||
``` | ||
## License | ||
## License | ||
@@ -89,0 +98,0 @@ (The MIT License) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
17232
310
1
116