Fixed opening of streams

This commit is contained in:
Jamie Hardt
2022-12-07 10:07:42 -08:00
parent 03bf50d496
commit 4c5754a1b8

View File

@@ -34,7 +34,7 @@ class WavInfoReader:
Create a new reader object.
:param path:
A filesystem path to the wav file you wish to probe or a
A pathlike object or IO to the wav file you wish to probe or a
file handle to an open file.
:param info_encoding:
@@ -45,25 +45,11 @@ class WavInfoReader:
The text encoding to use when decoding the string
fields of the Broadcast-WAV extension. Per EBU 3285 this is ASCII
but this parameter is available to you if you encounter a weirdo.
"""
self.info_encoding = info_encoding
self.bext_encoding = bext_encoding
if hasattr(path, 'read'):
self.get_wav_info(path)
self.url = 'about:blank'
self.path = repr(path)
else:
absolute_path = os.path.abspath(path)
#: `file://` url for the file.
self.url: pathlib.Path = pathlib.Path(absolute_path).as_uri()
self.path = absolute_path
#: Wave audio data format.
self.fmt :Optional[WavAudioFormat] = None
@@ -85,6 +71,20 @@ class WavInfoReader:
#: RIFF INFO metadata.
self.info :Optional[WavInfoChunkReader]= None
if hasattr(path, 'read'):
self.get_wav_info(path)
self.url = 'about:blank'
self.path = repr(path)
self.get_wav_info(path)
else:
absolute_path = os.path.abspath(path)
#: `file://` url for the file.
self.url: pathlib.Path = pathlib.Path(absolute_path).as_uri()
self.path = absolute_path
with open(path, 'rb') as f:
self.get_wav_info(f)