is-midi
v2.0.0
Published
Check if a Buffer/Uint8Array is a MIDI file
Downloads
25
Maintainers
Readme
is-midi

Check if a Buffer/Uint8Array is a MIDI file
Install
npm install is-midiUsage
Node.js
import { readFileSync } from 'node:fs';
import isMidi from 'is-midi';
const buffer = readFileSync('song.mid');
isMidi(buffer);
//=> trueBrowser
const response = await fetch('song.mid');
const buffer = new Uint8Array(await response.arrayBuffer());
isMidi(buffer);
//=> trueAPI
isMidi(buffer)
Returns true if the buffer is a MIDI file, false otherwise.
buffer
Type: Buffer | Uint8Array
The buffer to check. It only needs the first 4 bytes.
How it works
MIDI files start with the magic bytes MThd (hex: 4D 54 68 64). This package checks for those bytes to determine if a file is a MIDI file.
Related
- file-type - Detect the file type of a Buffer/Uint8Array
License
MIT © Chris Vogt
