node package manager
Stop writing boring code. Discover, share, and reuse within your team. Create a free org »

is-epub

is-epub Build Status

Check if a Buffer/Uint8Array is EPUB

Used by file-type.

Install

$ npm install --save is-epub

Usage

Node.js
var readChunk = require('read-chunk'); // npm install read-chunk 
var isEpub = require('is-epub');
var buffer = readChunk.sync('unicorn.epub', 0, 58);
 
isEpub(buffer);
//=> true 
Browser
var xhr = new XMLHttpRequest();
xhr.open('GET', 'unicorn.epub');
xhr.responseType = 'arraybuffer';
 
xhr.onload = function () {
    isEpub(new Uint8Array(this.response));
    //=> true 
};
 
xhr.send();

API

isEpub(buffer)

Accepts a Buffer (Node.js) or Uint8Array.

It only needs the first 58 bytes.

License

MIT © Sindre Sorhus