You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 948B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # is-jpg [![Build Status](https://travis-ci.org/sindresorhus/is-jpg.svg?branch=master)](https://travis-ci.org/sindresorhus/is-jpg)
  2. > Check if a Buffer/Uint8Array is a [JPEG](https://en.wikipedia.org/wiki/JPEG) image
  3. ## Install
  4. ```
  5. $ npm install is-jpg
  6. ```
  7. ## Usage
  8. ##### Node.js
  9. ```js
  10. const readChunk = require('read-chunk');
  11. const isJpg = require('is-jpg');
  12. const buffer = readChunk.sync('unicorn.jpg', 0, 3);
  13. isJpg(buffer);
  14. //=> true
  15. ```
  16. ##### Browser
  17. ```js
  18. const xhr = new XMLHttpRequest();
  19. xhr.open('GET', 'unicorn.jpg');
  20. xhr.responseType = 'arraybuffer';
  21. xhr.onload = () => {
  22. isJpg(new Uint8Array(this.response));
  23. //=> true
  24. };
  25. xhr.send();
  26. ```
  27. ## API
  28. ### isJpg(buffer)
  29. Accepts a Buffer (Node.js) or Uint8Array.
  30. It only needs the first 3 bytes.
  31. ## Related
  32. - [file-type](https://github.com/sindresorhus/file-type) - Detect the file type of a Buffer/Uint8Array
  33. ## License
  34. MIT © [Sindre Sorhus](https://sindresorhus.com)