Skip to content

Instantly share code, notes, and snippets.

@igilham
Created January 16, 2015 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igilham/0e070b6e11258a717154 to your computer and use it in GitHub Desktop.
Save igilham/0e070b6e11258a717154 to your computer and use it in GitHub Desktop.
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