Created
February 11, 2017 18:19
-
-
Save xaf/16f7a718e4d1b0f09bd56f63b8a3323f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import StringIO | |
| import tarfile | |
| tar = tarfile.open("test.tgz","w:gz") | |
| string = StringIO.StringIO() | |
| string.write("hello") | |
| string.seek(0) | |
| info = tarfile.TarInfo(name='foo') | |
| info.size=len(string.buf) | |
| tar.addfile(tarinfo=info, fileobj=string) | |
| info = tarfile.TarInfo(name='bar') | |
| info.type = tarfile.DIRTYPE | |
| tar.addfile(tarinfo=info) | |
| string2 = StringIO.StringIO() | |
| string2.write("hello2") | |
| string2.seek(0) | |
| info = tarfile.TarInfo(name='bar/baz') | |
| info.size=len(string2.buf) | |
| tar.addfile(tarinfo=info, fileobj=string2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment