Check if a Buffer/Uint8Array is a MIDI file
$ npm install is-midi
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
const xhr = new XMLHttpRequest();
xhr.open('GET', 'song.mid');
xhr.responseType = 'arraybuffer';
xhr.onload = () => {
isMidi(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
MIT © Chris Vogt