1

Tell me how to write bitstreams correctly

Here is my code, it works, but it seems to me that I am not writing data to the file correctly.

fd = stream.open()
filename = 'file.ts'
while True:
    data = fd.read(8192)
    file_output = open(filename, "ab")
    file_output.write(data)

fd is a data stream, it is replenished and, accordingly, I must read from it until it ends.

OWGrant24
  • 11
  • 2
  • 1
    What *seems* wrong with your code? – Woodford Jul 29 '21 at 22:33
  • fd = stream.open() in this line I am reading a stream from streamlink as a ts file. Next, I need to write it to a file while the stream is running. It's hard for me to think of how to do this in Python. – OWGrant24 Jul 29 '21 at 22:41
  • Let me clarify. You've said your code works. So what is your question? – Woodford Jul 29 '21 at 22:44
  • https://streamlink.github.io/api_guide.html from this api, I get a stream and I need to write it to a file. Yes, the code does not work correctly, but it works. I want to understand how to write a stream of bytes correctly while they are in the fd container. – OWGrant24 Jul 29 '21 at 22:48

0 Answers0