zipEntry.contentIterator([options])


  • options <Object>
    • verify <boolean> 验证条目的 CRC-32 校验和。默认值:true。
    • maxSize <number> 在解压任何内容之前,拒绝声明超过这么多未压缩字节的内容。**默认:**无限制。
  • 返回:<AsyncIterator> <Buffer> 个条目解压内容的块。

与 zipEntry.content() 不同,这不会将整个成员缓存在内存中。对于一个基于文件的条目(由 zipFile.get() 返回的条目),压缩字节会在迭代器被使用时从磁盘读取,而且不会保留任何内容;条目只有在其 ZipFile 打开时才有效。

🌐 Unlike zipEntry.content(), this does not buffer the whole member in memory. For a file-backed entry (one returned by zipFile.get()) the compressed bytes are read from disk as the iterator is consumed and nothing is retained; the entry is valid only while its ZipFile is open.

因为流式处理是用于任意大成员的有界内存路径,所以它不会像zipEntry.content()那样被zlib.getMaxZipContentSize()限制——那种默认设置是为了保护单次大分配,而流式处理永远不会进行这种分配。输出仍然按每个块的声明未压缩大小有限制;可以传入maxSize来施加明确的上限。

🌐 Because streaming is the bounded-memory path for arbitrarily large members, it is not capped by zlib.getMaxZipContentSize() the way zipEntry.content() is - that default guards a single large allocation, which streaming never makes. Output is still bounded per chunk to the declared uncompressed size; pass maxSize to impose an explicit ceiling.

对于没有压缩存储的内存条目,生成的块是该条目保留内容的零拷贝视图(见 zipEntry.rawContent);不要修改它们。

🌐 For an in-memory entry stored without compression, the yielded chunks are zero-copy views of the entry's retained content (see zipEntry.rawContent); do not mutate them.

生成的块在迭代器完成之前都是临时的。CRC-32 校验(以及最终声明大小的检查)只能在所有字节读取完之后才能进行,因此一个损坏或截断的条目会通过迭代器在最后一个块之后抛出异常来报告,而不是在第一个块之前。每个块仍然是有边界的,所以总量从不会超过声明的大小或 maxSize,但是如果消费者不应该对未验证的字节进行操作,就应该先缓存这些字节(或者使用 zipEntry.content(),它会在返回任何数据之前进行验证),而不是边收边处理块。

🌐 The yielded chunks are provisional until the iterator completes. CRC-32 verification (and the final declared-size check) can only run once every byte has been read, so a corrupt or truncated entry is reported by the iterator throwing after the last chunk, not before the first. Each chunk is still bounded so the total never exceeds the declared size or maxSize, but a consumer that must not act on unverified bytes should buffer them (or use zipEntry.content(), which verifies before returning anything) rather than processing chunks as they arrive.