Issue 19623: Support for writing aifc to unseekable file (original) (raw)
The aifc module documentation mentions that underlying file can be unseekable if the number of frames are specified.
When
used for writing, the file object should be seekable, unless you know ahead of
time how many samples you are going to write in total and use
:meth:writeframesraw
and :meth:setnframes
.
But this doesn't work.
import aifc f = aifc.open('/dev/stdout', 'w') f.setnchannels(1) f.setsampwidth(1) f.setframerate(8000) f.setcomptype(b'NONE', b'not compressed') f.setnframes(1) f.writeframesraw(b'\0') Traceback (most recent call last): File "", line 1, in File "/home/serhiy/py/cpython/Lib/aifc.py", line 695, in writeframesraw self._ensure_header_written(len(data)) File "/home/serhiy/py/cpython/Lib/aifc.py", line 763, in _ensure_header_written self._write_header(datasize) File "/home/serhiy/py/cpython/Lib/aifc.py", line 791, in _write_header self._form_length_pos = self._file.tell() OSError: [Errno 29] Illegal seek
Here is a patch which makes the code to conform with the documentation.