Commit dd407797 authored by Fabian Müller's avatar Fabian Müller
Browse files

Make file handling more thread-safe

parent 9954944e
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -676,9 +676,7 @@ def get_wav_file_info(filename: str) -> dict:

    """

    fid = open(filename, "rb")

    try:
    with open(filename, "rb") as fid:
        riff = fid.read(4)

        if riff == b"RIFF":
@@ -686,13 +684,13 @@ def get_wav_file_info(filename: str) -> dict:
        elif riff == b"RIFX":
            binary_format = ">"
        else:
            raise ValueError("No RIFF!")
            raise ValueError(f"Not a RIFF file: {filename}")

        wav_size = struct.unpack(f"{binary_format}I", fid.read(4))[0]

        wav_identifier = fid.read(4)
        if wav_identifier != b"WAVE":
            raise ValueError("No WAVE!")
            raise ValueError(f"Not a WAVE file: {filename}")

        fmt_chunk_id = fid.read(4)

@@ -715,9 +713,6 @@ def get_wav_file_info(filename: str) -> dict:
        else:
            raise ValueError("No or corrupt fmt chunk!")

    finally:
        fid.close()

    return {
        "size": wav_size,
        "format_tag": wav_format,