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

Python - Write json to BytesIO from dictionary object and store as compressed tar.gz

My code is mostly working but I am having a bit of trouble writing a tar file to a remote filesystem. The code below is supposed to serialize a large dictionary to json and write to a compressed file object. The named temporary file is optional as I…
gordon macmillan
  • 123
  • 3
  • 13
0
votes
0 answers

Python: tarfile library turning file into a binary file

My name is Luis and I would like to ask you question about the python library tarfile. When I archive a file with tarfile, it adds some extra information to the original file, turning it to a binary file. This happens only In the production systems,…
0
votes
1 answer

How to merge two tar gz BinaryIO in Python 3

I have two Binary I/O stream (both inherit of BufferedIOBase), which represent two tar archives compressed with gzip algorithm. Is there any effecient way to create a third one which is the combination of the two others ? I tried by converting both…
user5510840
0
votes
1 answer

Python 3.6, Windows 10 .tar.gz extraction not working

I have tried a couple of different spins on in it, but do not appear to be getting any results. Below are two attempts at extracting the contents of a .tar.gz archive to the same folder where the compressed archive is; For example I would start with…
gdogg371
  • 3,879
  • 14
  • 63
  • 107
0
votes
1 answer

Windows! Path String \ gets converted to \\\\

This Code works just fine on Ubuntu and MacOs but gives me headaches on windows. manifest_zip_path = Path(zip_path).name / Path("manifest") tar = tarfile.open(zip_path, "r:gz") f = tar.extractfile(str(manifest_zip_path)) There is a Path object…
ahv2j5dc
  • 11
  • 5
0
votes
0 answers

Tarfile won't open file

I have the following code snippet to extract an image from .tzg file: def read_raw_from_tar(tar_fn, fn): with tarfile.open(tar_fn) as f: m = f.getmember(fn) return f.extractfile(m).read() raw_bytes =…
user8354174
0
votes
2 answers

open corrupt tar file with python

I am downloading tar files from a ftp server with the help of python. However, now I am facing problems and getting the error "ReadError: unexpected end of data". I assume my file got corrupted. I can open the files outside python with the comment…
janema
  • 33
  • 1
  • 7
0
votes
0 answers

Extract a txz file inside a zipfile in Python

I have a zipfile which has the .txz file. Something like this: file1.zip | -- file2.txz | -- abc.txt I have used ZipFile to extract the contents of file1.zip as below: with zipfile.ZipFile(mainFile) as zf: …
user3762146
  • 205
  • 3
  • 13
0
votes
1 answer

Streaming files from a tar file in hdfs

I have tiff images stored in tar files in HDFS. I can download the tar file and stream from it in this way: tar = tarfile.open("filename.tar", 'r|') for tiff in tar: if tiff.isfile(): a = tar.extractfile(tiff).read() na =…
Ehsan Fathi
  • 598
  • 5
  • 21
0
votes
1 answer

How to convert tar file to tar.gz using Python only?

I looking for how converting tar file to tar.gz using only Python code? I have been tried many issues but nothing work https://docs.python.org/3.6/library/tarfile.html https://docs.python.org/3.6/library/gzip.html I obtain different error: with…
0
votes
3 answers

FileNotFoundError with absolute path when trying to read tarball

I am trying to read from a tar-file but despite specifying the absolute path i get a FileNotFoundError. This is the relevant portion of code: 1 from pathlib import Path 2 3 testPath = Path("G:/test.tar") 4 tar = tarfile.open(testPath, "r") 5…
Wolfone
  • 1,276
  • 3
  • 11
  • 31
0
votes
0 answers

writing csv to tarfile but with no extension inside

I'm trying to create a .csv file and then create a .gz file with the previous csv inside. The problem is that the .gz file is created with a file with the correct file name but without the .csv extension and I don't know how to solve it. This is the…
Rod0n
  • 1,019
  • 2
  • 14
  • 33
0
votes
1 answer

Extract file inside a .gz that's inside a .tar without unzipping the two

I need to extract .tex files from multiple .gz files that are inside a single .tar file. I wrote some code that does this successfully, but I am unzipping the .tar and every .gz file. Is there a way to avoid doing so much unzipping? I would like to…
brienna
  • 1,415
  • 1
  • 18
  • 45
0
votes
0 answers

Extract or read single file from remote TGZ archive using Python 3

i'm trying to download a single text file from a remote TGZ archive using Python 3, but at the moment i only can doing it downloading the whole TGZ in memory and then using tarfile as a local file, the problem is than i can't use the mode r:gz when…
0
votes
1 answer

Python 3.5: Tarfile append mode "ReadError" on empty tar

I have encountered a problem working with the creation of new tarfiles using the latest python 3.5 package and its tarfile module. This problem is similar to those discussed here and here. In the former case the suggested solution returns the error…
zPatches
  • 1
  • 4