Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An untested experimental program to stream files one packet at a time, with a pause feature. This will certainly be very slow if it works at all.
#!/usr/local/bin/env python
import signal
import sys
packet_size = 188
position = 0
paused = False
def pause_handler(signal, frame):
paused = not paused
signal.signal(signal.SIGINT, pause_handler)
infile = sys.stdin.buffer
outfile = sys.stdout.buffer
data = infile.read(packet_size)
position += 1
while data:
if paused:
signal.pause() # sleep until any signal is received
outfile.write(data)
data = infile.read(packet_size)
position += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.