Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate gzipped files with Python, on Windows

Is there a memory-efficient way to concatenate gzipped files, using Python, on Windows, without decompressing them?

According to a comment on this answer, it should be as simple as:

cat file1.gz file2.gz file3.gz > allfiles.gz

but how do I do this with Python, on Windows?

like image 903
BioGeek Avatar asked Dec 25 '22 22:12

BioGeek


1 Answers

Just keep writing to the same file.

with open(..., 'wb') as wfp:
  for fn in filenames:
    with open(fn, 'rb') as rfp:
      shutil.copyfileobj(rfp, wfp)
like image 111
Ignacio Vazquez-Abrams Avatar answered Jan 10 '23 03:01

Ignacio Vazquez-Abrams