Questions tagged [tarfile]

either a tar archive file or a Python module used to handle tar archive files

The term "tar file" can refer to either an archive file created with the UNIX tar command (also called a tarball) or the Python tarfile module that is used to read, write, and manage these files.

Resources

Related Tags

231 questions
6
votes
2 answers

preserving file permission when creating a tarball with Python's tarfile

hello stackoverflowers, I want to preserve the original file permissions when using Python's tarfile module. I have quite a few executable files that lose their permissions once the tarball is extracted. I'm doing something like this: import…
user3352256
  • 109
  • 2
  • 5
5
votes
1 answer

Python: Renaming member in a tar file during extraction

Premise I have a directory /foo/bar I have a tar file containing the directory baz Problem Extracting the contents of baz in the archive to /foo/bar Example The archive contains: baz/ file1.txt The source directory contains: foo/ bar/ …
Nicklas A.
  • 6,501
  • 7
  • 40
  • 65
5
votes
1 answer

What is the fundamental difference between tar (Unix) and tarfile (Python)?

What is the fundamental difference between tarring a folder using tar on Unix and tarfile in Python that results in a different file size? In the example below, there is an 8.2 MB difference. I'm currently using a Mac. The folder in this example…
Simon1
  • 445
  • 4
  • 12
5
votes
1 answer

Need help reading image files in tar file using python

I have a tar file which has number of folders within it. In each folder there are number of image files. I need to write a python script which will read each image file and perform some action on the image (ex: thresholding etc.,) and save the image…
Harathi
  • 999
  • 2
  • 7
  • 8
5
votes
2 answers

In python, if extract a tar.gz file, how to get or set the name of the result file

My question is like: when use: import tarfile tar = tarfile.open("sample.tar.gz") tar.extractall() tar.close() if the file before compress called "sampleFolder", after I doing the above steps, how to return the "sampleFolder" name, better with its…
STR
  • 75
  • 1
  • 1
  • 7
5
votes
1 answer

Python: tarfile stream

I would like to read some files from a tarball and save it to a new tarball. This is the code I wrote. archive = 'dum/2164/archive.tar' # Read input data. input_tar = tarfile.open(archive, 'r|') tarinfo = input_tar.next() input_tar.close() # Write…
user378147
5
votes
1 answer

Tarfile create xz file

i have noticed that tarfile doesn't have a w:xz option or something similar,is there any way to create a xz file?i have this code in python dir=tkFileDialog.askdirectory(initialdir="/home/david") if x.get()=="gz": tar =…
Ulrok
  • 89
  • 2
  • 6
5
votes
2 answers

Uncompress an tar.bz2 file with Python tarfile module

I have many files with the extension "tar.bz2" and I want to uncompress them. So I use the "tarfile" module as explained here : https://docs.python.org/3/library/tarfile.html. I try the following code : import tarfile tar =…
Julien
  • 699
  • 3
  • 14
  • 30
5
votes
1 answer

combining tempfile and tarfile with python?

say we have a tempfile to which we could write some output. but for some strange reason we want it to be compressed by some of archiving techniques, tar for instance, by tempfile I mean the one which has not visiable name created by…
user3663978
  • 121
  • 2
  • 5
4
votes
1 answer

How can I read from a corrupted tar.bz2 file in Python?

I have a program which saves its output to a tar.bz2 file as it works. I have a python script which processes that data. I'd like to be able to work with the output if the first program is interrupted — or just run the python script against it while…
mattdm
  • 2,082
  • 25
  • 39
4
votes
3 answers

How to extract a specific file from the .tar archive in python?

I have created a .tar file on a Linux machine as follows: tar cvf test.tar test_folder/ where the test_folder contains some files as shown below: test_folder |___ file1.jpg |___ file2.jpg |___ ... I am unable to programmatically extract the…
Swaroop
  • 1,219
  • 3
  • 16
  • 32
4
votes
1 answer

Saving file object using matplotlib savefig, creating tar file from multiple svg figures

I have created multiple figures using python with matplotlib. PyQt5 is used as a backend to display the figures. I am saving the figures in svg format using savefig. My problem is that I would like to create a single zip file containing all of the…
bgro
  • 65
  • 6
4
votes
1 answer

Python: using filter in tarfile

I am writing a backup script which uses tarfile module. I am a beginner in python. Here is part of my script - So I have a list of paths that need to be archived in tar.gz. seeing this post, I came up with following. Now archive gets created but…
akya
  • 99
  • 1
  • 10
4
votes
1 answer

Python tarfile: how to use tar+gzip compression with follow symbolic link?

How could I use tar+gzip compression with "follow symbolic link" feature in Python 3.4? The problem is: tarfile.open() supports "w:gz" mode but does not support "dereference" option tarfile.tarfile() supports "dereference" but does not support…
Balint
  • 45
  • 8
4
votes
0 answers

Get bytes for tarfile in Python

How do I get the binary representation of a tarfile object in Python? Right now I am doing the following, but this involves "copying": with BytesIO() as out_buffer: with tarfile.open(fileobj=out_buffer, mode='w') as newtar: for member in…
Alex Rothberg
  • 10,243
  • 13
  • 60
  • 120
1
2
3
15 16