MIDI
audio/midi
Magic Bytes
Offset: 0
4D 54 68 64
The Musical Instrument Digital Interface (MIDI) is a technical standard and file format maintained by the MIDI Association to describe musical performance data. Unlike digital audio recordings, this format stores instruction sets for pitch, velocity, and notation, making it essential for electronic music production and notation software. Introduced in 1983, it remains an industry standard, presenting minimal security risks as it contains data instructions rather than executable code.
Validation Code
How to validate .midi files in Python
Python
def is_midi(file_path: str) -> bool:
"""Check if file is a valid MIDI by magic bytes."""
signature = bytes([0x4D, 0x54, 0x68, 0x64])
with open(file_path, "rb") as f:
return f.read(4) == signature
How to validate .midi files in Node.js
Node.js
function isMIDI(buffer: Buffer): boolean {
const signature = Buffer.from([0x4D, 0x54, 0x68, 0x64]);
return buffer.subarray(0, 4).equals(signature);
}
Go
func IsMIDI(data []byte) bool {
signature := []byte{0x4D, 0x54, 0x68, 0x64}
if len(data) < 4 {
return false
}
return bytes.Equal(data[:4], signature)
}
API Endpoint
GET
/api/v1/midi
curl https://filesignature.org/api/v1/midi