"""Identify WAV file formats. This is used only to give better error messages in the event that a sound file is not loadable by Pygame. This is based on the 'magic' information for the 'file' command, at https://github.com/file/file/blob/86e34444a26860f2ad9895a2d77cb16d1ca4c48b/magic/Magdir/riff """ from struct import unpack_from class MagicReader: """Interface to reading the magic numbers in a file's header.""" def __init__(self, path): with open(path, 'rb') as f: self.bytes = f.read(64 * 1024) def read_bytes(self, offset, length=4): return self.bytes[offset:offset + length] def read_leshort(self, offset): """Read an unsigned short at the given offset.""" return unpack_from('