1.0.0 • Published 6 years ago

is-midi v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

is-midi Build Status codecov

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