is-midi
v1.0.0
Published
Check if a Buffer/Uint8Array is a MIDI file
Downloads
4
Maintainers
Readme
is-midi
Check if a Buffer/Uint8Array is a MIDI file
Install
$ npm install is-midi
Usage
Node.js
const readChunk = require('read-chunk'); // npm install read-chunk
const isMidi = require('is-midi');
const buffer = readChunk.sync('song.mid', 0, 4);
isMidi(buffer);
//=> true
Browser
const xhr = new XMLHttpRequest();
xhr.open('GET', 'song.mid');
xhr.responseType = 'arraybuffer';
xhr.onload = () => {
isMidi(new Uint8Array(this.response));
//=> true
};
xhr.send();
API
isMidi(buffer)
Accepts a Buffer (Node.js) or Uint8Array.
It only needs the first 4 bytes.
Related
- file-type - Detect the file type of a Buffer/Uint8Array
License
MIT © Chris Vogt