我想创建一个tar文件并通过管道将其发送到http上传。
然而,似乎python tarfile模块执行了查找,这使得它不可能通过管道进入下一个进程。
以下是代码
tar = tarfile.open('named_pipe', mode='w')
tar.add('file1')
p.close()' named_pipe‘是一个由mkfifo命令创建的命名管道文件,当我运行它并在另一个终端中cat named_pipe时,我得到了以下错误
tar = tarfile.open('named_pipe', mode='w')
File "/usr/lib/python2.7/tarfile.py", line 1695, in open
return cls.taropen(name, mode, fileobj, **kwargs)
File "/usr/lib/python2.7/tarfile.py", line 1705, in taropen
return cls(name, mode, fileobj, **kwargs)
File "/usr/lib/python2.7/tarfile.py", line 1566, in __init__
self.offset = self.fileobj.tell()
IOError: [Errno 29] Illegal seek有什么想法吗?
发布于 2014-08-16 03:49:16
我们做了类似的事情,但从另一方面。我们有一个web应用程序,它将tarfile提供给访问者浏览器,这意味着我们通过http会话对其进行流式传输。诀窍是将打开的和可写的文件句柄传递给tarfile.open()调用,并将模式设置为"w|“。如下所示:
# assume stream is set to your pipe
with tarfile.open(name="upload.tar",
mode = "w|",
fileobj = stream,
encoding = 'utf-8') as out:
out.add(file_to_add_to_tar)https://stackoverflow.com/questions/25333067
复制相似问题