Skip to content

Instantly share code, notes, and snippets.

@leth
leth / streaming-tar.py
Last active August 12, 2016 14:24 — forked from chipx86/streaming-tar.py
Sample code to build a tar chunk-by-chunk and stream it out all at once.
#!/usr/bin/env python
#
# Building a tar file chunk-by-chunk.
#
# This is a quick bit of sample code for streaming data to a tar file,
# building it piece-by-piece. The tarfile is built on-the-fly and streamed
# back out. This is useful for web applications that need to dynamically
# build a tar file without swamping the server.
from io import BytesIO
from os import walk
@leth
leth / gist:9291261
Last active August 29, 2015 13:56 — forked from sloria/gist:5895687
f = open('file.txt', 'w')
f.write('hi')
f.close()
# Better
with open('file.txt', 'w') as f:
f.write('hi')
with pytest.raises(ValueError):
int('hi')