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
4
votes
1 answer

tarfile.ReadError: file could not be opened successfully

I have the following piece of code to open a .tgz file, but I'm getting tarfile.ReadError: file could not be opened successfully. fp = tarfile.open('file.tgz', 'r') print fp.list() fp.close() I can extract this archive using "tar -xvzf file.tgz."…
Felipe
  • 144
  • 1
  • 3
  • 11
4
votes
1 answer

python tarfile writes tar to pipe

I want to create a tar file and pipe it to a http upload. However, seems python tarfile module performs seek which make it impossible to pipe to the next process. Here is the code tar = tarfile.open('named_pipe',…
Lin Linf
  • 61
  • 2
4
votes
1 answer

Read contents of .tar.gz file from website into a python 3.x object

I am new to python. I can't figure out what I am doing wrong when trying to read the contents of .tar.gz file into python. The tarfile I would like to read is hosted at the following web…
Chris
  • 3,401
  • 5
  • 33
  • 42
4
votes
1 answer

How does one add string to tarfile in Python3

I have problem adding an str to a tar arhive in python. In python 2 I used such method: fname = "archive_name" params_src = "some arbitrarty string to be added to the archive" params_sio = io.StringIO(params_src) archive =…
luk32
  • 15,812
  • 38
  • 62
3
votes
2 answers

Extract only jpg files from a .tar.gz file using python

Problem Summary: In one of my folder I have .tar.gz file and I need to extract all the images (.jpg & .png) from it. But I have to use the .tar.gz extension (using path to directory) to extract it and not by using the usual way of giving the input…
3
votes
2 answers

Can't map a function to tarfile members in parallel

I have a tarfile containing bz2-compressed files. I want to apply the function clean_file to each of the bz2 files, and collate the results. In series, this is easy with a loop: import pandas as pd import json import os import bz2 import…
3
votes
3 answers

Python: Delete file from the TAR archive using tarfile

Is it possible to remove from a TAR archive some file using tarfile? For example: If an x.tar file includes the files a.txt, b.txt and c.txt, is it possible to remove a.txt? In other words: does any python solution exist to achieve something like…
jwalkiew
  • 61
  • 1
  • 5
3
votes
0 answers

Tarfile extracting path cannot include special characters

I want to extract tarfile to it's own path but if the file's path contains any special characters(like ö). If I don't give extracting path, it extracts tarfile to my project directory. Here is my code: # -*- coding: utf-8 -*- import tarfile,…
Ayse
  • 43
  • 1
  • 5
3
votes
2 answers

Organizing files in tar bz2 file with python

I have about 200,000 text files that are placed in a bz2 file. The issue I have is that when I scan the bz2 file to extract the data I need, it goes extremely slow. It has to look through the entire bz2 file to fine the single file I am looking for.…
xZel
  • 65
  • 1
  • 1
  • 7
3
votes
2 answers

Python: how to create tar file and compress it on the fly with external module, using different compression methods not available in tarfile module?

I'm trying to set up a code to pack a few big files (from tens to hundreds of gigabytes) into one archive. The compression methods that supported in tarfile module are a bit slow for such a big amount of data, so I would like to use some external…
3
votes
0 answers

What "Extraction Issues" does TarFile.extract() not take care of?

There's this note on the docs for TarFile.extract(): Note: The extract() method does not take care of several extraction issues. In most cases you should consider using the extractall() method. What "extraction issues" is it referring to? Why…
ArtOfWarfare
  • 20,617
  • 19
  • 137
  • 193
3
votes
2 answers

High memory usage with Pythons native tarfile lib

I'm working in a memory constrained environment and uses a Python script with tarfile library (http://docs.python.org/2/library/tarfile.html) to continuously make backups of log files. As the number of log files have grown (~74 000) I noticed that…
Niklas9
  • 8,816
  • 8
  • 37
  • 60
3
votes
1 answer

Why does tarfile.extractall ignore errors by default?

Python's tarfile module ignores errors during extraction by default, unless errorlevel is set to either 1 or 2 (or debug to 1 if only error messages need to be printed). Try doing a mkdir /tmp/foo && sudo chown root /tmp/foo && chmod a-w /tmp/foo…
Sridhar Ratnakumar
  • 81,433
  • 63
  • 146
  • 187
3
votes
1 answer

Python tarfile - check if file in tar exists outside (i.e., already been extracted)

I'm new to stackoverflow. Sorry if this post is redundant but I haven't found the answer yet. Also, I'm fairly new to Python. I'd like to extract files from a tar file if they do not already exist in the root directory where the tar file exists.…
dgj32784
  • 673
  • 1
  • 7
  • 13
3
votes
3 answers

Checking tarfile integrity in Python

I'm working on converting my backup script from shell to Python. One of the features of my old script was to check the created tarfile for integrity by doing: gzip -t . This seems to be a bit tricky in Python. It seems that the only way to do this,…
Kaurin
  • 294
  • 1
  • 3
  • 9
1 2
3
15 16