Dumping JSON directly into a tarfile
问题 I have a large list of dict objects. I would like to store this list in a tar file to exchange remotely. I have done that successfully by writing a json.dumps() string to a tarfile object opened in 'w:gz' mode. I am trying for a piped implementation, opening the tarfile object in 'w|gz' mode. Here is my code so far: from json import dump from io import StringIO import tarfile with StringIO() as out_stream, tarfile.open(filename, 'w|gz', out_stream) as tar_file: for packet in json_io_format