创建一个streamable和(有些)seecable.zip文件
zipseeker的Python项目详细描述
类似系统/项目:
- 这是Nginx zip module。只为nginx,所以 不能与其他Web服务器一起使用。
- python-zipstream。没有 支持预先计算文件大小或查看文件。
用法:
importzipseeker# Create an indexfp=zipseeker.ZipSeeker()fp.add('some/file.txt')fp.add('another/file.txt','file2.txt')# Calculate the total file size, e.g. for the Content-Length HTTP header.contentLength=fp.size()# Calculate the last-modified date, e.g. for the Last-Modified HTTP header.lastModified=fp.lastModified()# Send the ZIP file to the client# Optionally add the start and end parameters for range requests.# Note that the ZIP format doesn't support actually skipping parts of the file,# as it needs to calculate the CRC-32 of every file at the end of the file.fp.writeStream(outputFile)
为什么?
而zip文件的文件大小通常无法预先计算,因为 压缩,这实际上是可选的。头部本身也有一个漂亮的 大小不变。这意味着整个文件可以有预定的文件大小 (和modtime)。
当您希望提供大型目录的zip下载 不可压缩文件(如图像)。我创建此媒体的特定用例 文件的目的是提供整个相册的下载 在电子邮件中请求下载链接的不便,使用大量系统 用于创建临时文件并必须删除这些文件的资源 之后。
当然,可以只流化一个zip文件,但这不会提供任何 文件下载的进度指示,当然不支持Range requests。
有关详细信息,请参见Nginx zip module。
待办事项
- 在文件中实现实际的搜索-这应该是可行的。
- 使用可由调用模块共享的CRC-32高速缓存。