python流tarfile成员到命名管道

时间:2018-11-02 14:11:47

标签: python linux file io

我试图打开一个tarfile,然后直接通过命名管道将成员流式传输到外部应用程序,而不是对整个程序进行解压缩。

    with tarfile.open("my_tarfile.tar.gz") as tf:
        for member in tf.getmembers():
            if member.isfile():
                with tf.extractfile(member) as file_obj:
                    for line in file_obj:
                        # Can stream the file - yay! 

我希望能够以某种方式将file_obj连接到通过命名管道在python内部启动的外部进程-我想执行以下操作:

    with tarfile.open("my_tarfile.tar.gz") as tf:
        for member in tf.getmembers():
            if member.isfile():
                with tf.extractfile(member) as file_obj:
                    os.mkfifo("the_output_stream")
                    # 1. Somehow connect file_obj -> the_output_stream
                    # 2. Kick off process which consumes "the_output_stream"

任何人都对如何/是否有可能有任何想法?

0 个答案:

没有答案