Skip to content
Advertisement

python subprocess with gzip

I am trying to stream data through a subprocess, gzip it and write to a file. The following works. I wonder if it is possible to use python’s native gzip library instead.

JavaScript

THE QUESTION: How do I do this instead .. where the gzip package of python is used? I’m mostly curious to know why the following gives me a text files (instead of a compressed binary version) … very odd.

JavaScript

Advertisement

Answer

subprocess writes to oFid.fileno() but gzip returns fd of underlying file object:

JavaScript

To enable compression use gzip methods directly:

JavaScript

Example

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement