Skip to content

Instantly share code, notes, and snippets.

@slackorama
Created September 22, 2012 00:36
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 slackorama/3764666 to your computer and use it in GitHub Desktop.
Save slackorama/3764666 to your computer and use it in GitHub Desktop.
import zlib
import sys
import subprocess
import tempfile
d = zlib.decompressobj(16+zlib.MAX_WBITS)
def bob(data):
for value in data:
print(value)
def load_stream(input_stream):
while True:
data = input_stream.read(1024*8)
if not data:
break
yield d.decompress(data)
if __name__ == '__main__':
f = tempfile.NamedTemporaryFile(delete=False)
name = f.name
p1 = subprocess.Popen(['cat', '/home/seth/.emacs.d/init.el'],
stdout=subprocess.PIPE)
p2 = subprocess.Popen(['/bin/gzip', '-c'], stdin=p1.stdout,
stdout=f)
p1.stdout.close()
p2.communicate()[0]
f.close()
print(name)
# print(p2.communicate()[0])
# # becomes
# p1 = Popen(["dmesg"], stdout=PIPE)
# p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
# p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
# output = p2.communicate()[0]
# print(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment