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
0
votes
2 answers

Append a folder to gzip in memory using python

I have a tar.gz file downloaded from s3, I load it in memory and I want to add a folder and eventually write it into another s3. I've been trying different approaches: from io import BytesIO import gzip buffer =…
3nomis
  • 1,175
  • 1
  • 9
  • 30
0
votes
1 answer

How to extract the content of `*.tar.gz` dynamically

I have quite big *.tar.gz file (10Gb) that contains individuals files (no sub-folders). In Jupyter Notebook it takes several hours to untar this archive. Once all files are extracted, I need to upload them into a storage location. This is what I…
Fluxy
  • 2,838
  • 6
  • 34
  • 63
0
votes
1 answer

Is there way to chain tarfile generation and gnupg encryption in python?

I want to make a tar file of a directory and encrypt the tar file. Currently, I create a tar file and save it into HDD. And then, I read the tar file to encrypt and save the encrypted version. But my problem is I don't need the tar file and erase it…
hbadger19042
  • 151
  • 1
  • 8
0
votes
1 answer

how to mimic `--numeric-owner` in tarfile?

with tar command we can use tar --numeric-owner -cf - test | tee to make sure in tar data it use number to represent owner:group. How can we do this in python3's tarfile? It seems only extract mentioned numeric owner.
Wang
  • 7,250
  • 4
  • 35
  • 66
0
votes
1 answer

python tarfile created an extra @PaxHeader file and cause error Cannot utime: Operation not permitted

I have a lambda function that unpack a tgz file, replace the content and filename, and then re-pack it into a new tgz file. If I download the new file from s3 and unpack it locally using 7z on Windows or tar xvzf .tgz on Ubuntu, it…
Shawn
  • 5,130
  • 13
  • 66
  • 109
0
votes
2 answers

Python3: f.read() in Tarfile returns bytes instead of a file-like object and it passes empty file

I am having issue with passing file-like object of a tgz file in Python. here is how my code looks like: backup = tarfile.open(backup_file, mode='r:gz') for f in backup.getmembers(): if f.name.endswith('.xml'): ff = f.name …
rasekh64
  • 1
  • 1
0
votes
2 answers

Nested tar is created while creating simple tar.gz in python

I have tried below code to create simple tar file of all files present at given directory using python. In directory D:/tmp/ there are some regular files only and no sub-directories inside. import os import tarfile def createTar(path, tar_name): …
Girish
  • 366
  • 3
  • 15
0
votes
1 answer

How to include directory while compressing a tar.gz file in python?

Here's what i'm trying to do : import tarfile path = os.path.join(archive_path,"package.tar.gz") tar_package = tarfile.open(path, "w:gz") os.chdir(os.path.join(archive_path, "package")) for name in os.listdir("."): …
0
votes
1 answer

Python3 - how to write tarfile to a different directory?

I am trying to do a backup of directory in variable target_path to a file assigned in variable archive_name.tar.gz and write that file to a directory other than the current directory. The code below works but places the output in the current working…
Chris
  • 11
  • 2
0
votes
1 answer

Opening .tgz files with tarfile on Mac os X

I'm studying the book Hands-On Machine Learning with Scikit-Learn and TensorFlow, and in the first project, as you probably know, it's going to deal with a housing dataset. When I want to open the housing.tgz with tarfile, I get the error…
0
votes
1 answer

Extract lzma compressed tar archive members without writing to disk

I have a nested tar file 2 tars deep. The outermost tar is gpg encrypted and not compressed. The inner tar is lzma. Working with the innermost tar from disk I don't have any problems. Passing the inner most tar.xz file directly to with…
b0bu
  • 1,062
  • 1
  • 9
  • 24
0
votes
0 answers

Why tarfile.open and tarfile.extractall methods raise errors?

I am learning Python and related modules. Here are my scripts. import tarfile from six.moves import urllib data_path = "./datasets/housing/" file = "housing.tgz" data_path_file = data_path + file tar_file = tarfile.open(data_path_file) # tested…
Leon
  • 444
  • 2
  • 15
0
votes
1 answer

Is it possible to remove characters from a compressed file without extracting it?

I have a compressed file that's about 200 MB, in the form of a tar.gz file. I understand that I can extract the xml files in it. It contains several small and one 5 GB xml file. I'm trying to remove certain characters from the xml files. So my very…
fafz
  • 81
  • 7
0
votes
2 answers

Creating a tar stream in memory from multiple file byte streams

I'm trying to create a tar stream in memory add files to it and then save it to S3. But there is some issue and the files inside the ta have zero size. Can any one please advise? Code snippet below- def tar_and_upload(bucket, keys, dest_bucket): …
lalatnayak
  • 160
  • 1
  • 6
  • 21
0
votes
2 answers

How to exclude specific subfolders from the generated tar file?

I am using Python 3 with the tarfile module to compress some folders (with subfolders). What I need to do: to set a couple of subfolders to be excluded from the final tar file. For example, say my folders looked like: dir/ ├── subdirA │   ├──…