静态方法:zlib.ZipEntry.createStream(filename, source[, options])
🌐 Static method: zlib.ZipEntry.createStream(filename, source[, options])
filename<string> 存档中条目的名称。不能以/结尾。source<AsyncIterable> 将条目的未压缩内容作为Uint8Array块输出。options<Object>- 返回:ZipEntry
创建一个条目,其内容在由 zlib.createZipArchive() 序列化时会实时压缩,而不会在内存中缓存 source。它的 size、compressedSize 和 crc32 只有在序列化完成后才可用。没有同步对应项:流式条目只有在异步、逐步生成的 source 场景下才有意义。
🌐 Creates an entry whose content is compressed on the fly as it is serialized
by zlib.createZipArchive(), without buffering source in memory. Its
size, compressedSize, and crc32 only become available once
serialization has finished. There is no synchronous counterpart: streaming
entries only make sense with an asynchronous, incrementally-produced
source.
source 只会在序列化时被耗尽一次。在那之前,这个条目没有可读内容,所以 zipEntry.content()、zipEntry.contentSync() 和 zipEntry.contentIterator() 会抛出 ERR_INVALID_STATE。如果通过将它添加到可写的 ZipFile 并使用 zipFile.addEntry()(或 addEntrySync())来序列化它,那么它会就地提升为一个指向刚写入副本的文件支持条目,因此只要 ZipFile 保持打开,它就可以被读取(并且可以再次序列化)。用任何其他方式序列化(例如直接通过 zlib.createZipArchive())会让它耗尽且不可读。
因为 source 可能持有操作系统资源(比如一个文件读取流),所以流式条目是可释放的:它的 Symbol.dispose 和 Symbol.asyncDispose 方法会销毁 source,如果它还没有被使用的话。传递给归档的条目会由该归档释放(见 zlib.createZipArchive());只有在条目创建后从未交给归档时,才直接释放它。对于非流式条目,释放操作是无效的——特别是基于文件的条目从不会关闭它借用的 ZipFile 描述符。
🌐 Because source may hold an operating-system resource (a file read stream,
say), a streaming entry is disposable: its Symbol.dispose and
Symbol.asyncDispose methods destroy source if it has not been consumed.
An entry passed to an archive is disposed by that archive (see
zlib.createZipArchive()); dispose an entry directly only when it was
built but never handed to one. Disposal is a no-op for non-streaming entries -
in particular a file-backed entry never closes the ZipFile descriptor it
borrows.