Skip to content

Instantly share code, notes, and snippets.

@vsudilov
Created June 5, 2015 18:15
Show Gist options
  • Save vsudilov/cc25a6eee101a375bfed to your computer and use it in GitHub Desktop.
Save vsudilov/cc25a6eee101a375bfed to your computer and use it in GitHub Desktop.
in-memory tarfile with in-memory contents
tar_fileobj = io.BytesIO()
with tarfile.open(fileobj=tar_fileobj, mode="w|") as tar:
my_content = "abdef".encode('utf-8')
tf = tarfile.TarInfo("my_file_name")
tf.size = len(my_content)
tar.addfile(tf, io.BytesIO(my_content))
tar_fileobj.seek(0)
@borisevich-a-v
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment