Check if a Buffer/Uint8Array is a TIFF image
$ npm install is-tif
import {readChunkSync} from 'read-chunk';
import isTif from 'is-tif';
const buffer = readChunkSync('unicorn.tif', {length: 4});
isTif(buffer);
//=> true
const xhr = new XMLHttpRequest();
xhr.open('GET', 'unicorn.tif');
xhr.responseType = 'arraybuffer';
xhr.onload = () => {
isTif(new Uint8Array(this.response));
//=> true
};
xhr.send();
Accepts a Buffer
(Node.js) or Uint8Array
.
It only needs the first 4 bytes.
- file-type - Detect the file type of a Buffer/Uint8Array