Comparing version 1.0.1 to 2.0.0
27
index.js
@@ -1,15 +0,18 @@ | ||
'use strict'; | ||
module.exports = function (buf) { | ||
if (!buf || buf.length < 4) { | ||
export default function isTif(buffer) { | ||
if (!buffer || buffer.length < 4) { | ||
return false; | ||
} | ||
return (buf[0] === 73 && | ||
buf[1] === 73 && | ||
buf[2] === 42 && | ||
buf[3] === 0) || | ||
(buf[0] === 77 && | ||
buf[1] === 77 && | ||
buf[2] === 0 && | ||
buf[3] === 42); | ||
}; | ||
return ( | ||
buffer[0] === 73 | ||
&& buffer[1] === 73 | ||
&& buffer[2] === 42 | ||
&& buffer[3] === 0 | ||
) | ||
|| ( | ||
buffer[0] === 77 | ||
&& buffer[1] === 77 | ||
&& buffer[2] === 0 | ||
&& buffer[3] === 42 | ||
); | ||
} |
{ | ||
"name": "is-tif", | ||
"version": "1.0.1", | ||
"description": "Check if a Buffer/Uint8Array is a TIFF image", | ||
"license": "MIT", | ||
"repository": "sindresorhus/is-tif", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "http://sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"tif", | ||
"tiff", | ||
"graphics", | ||
"image", | ||
"img", | ||
"pic", | ||
"picture", | ||
"photo", | ||
"type", | ||
"detect", | ||
"check", | ||
"is", | ||
"exif", | ||
"binary", | ||
"buffer", | ||
"uint8array" | ||
], | ||
"devDependencies": { | ||
"mocha": "*", | ||
"read-chunk": "^1.0.0" | ||
} | ||
"name": "is-tif", | ||
"version": "2.0.0", | ||
"description": "Check if a Buffer/Uint8Array is a TIFF image", | ||
"license": "MIT", | ||
"repository": "sindresorhus/is-tif", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"tif", | ||
"tiff", | ||
"graphics", | ||
"image", | ||
"img", | ||
"pic", | ||
"picture", | ||
"photo", | ||
"type", | ||
"detect", | ||
"check", | ||
"is", | ||
"exif", | ||
"binary", | ||
"buffer", | ||
"uint8array" | ||
], | ||
"devDependencies": { | ||
"ava": "^3.15.0", | ||
"read-chunk": "^4.0.0", | ||
"xo": "^0.44.0" | ||
} | ||
} |
@@ -1,15 +0,11 @@ | ||
# is-tif [![Build Status](https://travis-ci.org/sindresorhus/is-tif.svg?branch=master)](https://travis-ci.org/sindresorhus/is-tif) | ||
# is-tif | ||
> Check if a Buffer/Uint8Array is a [TIFF](http://en.wikipedia.org/wiki/Tagged_Image_File_Format) image | ||
> Check if a Buffer/Uint8Array is a [TIFF](https://en.wikipedia.org/wiki/TIFF) image | ||
Used by [image-type](https://github.com/sindresorhus/image-type). | ||
## Install | ||
```sh | ||
$ npm install --save is-tif | ||
``` | ||
$ npm install is-tif | ||
``` | ||
## Usage | ||
@@ -20,6 +16,7 @@ | ||
```js | ||
var readChunk = require('read-chunk'); // npm install read-chunk | ||
var isTif = require('is-tif'); | ||
var buffer = readChunk.sync('unicorn.tif', 0, 4); | ||
import {readChunkSync} from 'read-chunk'; | ||
import isTif from 'is-tif'; | ||
const buffer = readChunkSync('unicorn.tif', {length: 4}); | ||
isTif(buffer); | ||
@@ -32,7 +29,7 @@ //=> true | ||
```js | ||
var xhr = new XMLHttpRequest(); | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open('GET', 'unicorn.tif'); | ||
xhr.responseType = 'arraybuffer'; | ||
xhr.onload = function () { | ||
xhr.onload = () => { | ||
isTif(new Uint8Array(this.response)); | ||
@@ -45,3 +42,2 @@ //=> true | ||
## API | ||
@@ -51,9 +47,8 @@ | ||
Accepts a Buffer (Node.js) or Uint8Array. | ||
Accepts a `Buffer` (Node.js) or `Uint8Array`. | ||
It only needs the first 4 bytes. | ||
## Related | ||
## License | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) | ||
- [file-type](https://github.com/sindresorhus/file-type) - Detect the file type of a Buffer/Uint8Array |
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
17
Yes
2916
3
51