zlib.createZipArchiveSync(entries[, options])


稳定性: 1.0 - 早期开发

ZIP 压缩档案 API 是实验性的。第一次使用它的任何部分(包括这个函数)都会发出实验性警告;仅仅导入 node:zlib 不会。

🌐 The ZIP archive API is experimental. Using any part of it (this function among them) emits an experimental warning the first time; merely importing node:zlib does not.

zlib.createZipArchive() 的同步版本会阻塞 Node.js 事件循环以及后续的 JavaScript 执行,直到整个归档(包括任何 deflate 处理)完成;只在同步执行合适的情况下使用(例如短期脚本或启动代码),不要在必须保持响应的代码中使用。entries 必须是一个普通(同步的)Iterable——使用 zlib.ZipEntry.createStream() 创建的流式条目在轮到序列化时会报错,因为耗尽其异步源没有同步的对应方法。

🌐 The synchronous version of zlib.createZipArchive(). Blocks the Node.js event loop and further JavaScript execution until the whole archive (including any deflate passes) has been produced; use only where synchronous execution is appropriate (for example, short-lived scripts or startup code), not in code that must stay responsive. entries must be a plain (synchronous) Iterable - a streaming entry created with zlib.ZipEntry.createStream() throws when its turn to serialize comes up, since draining its asynchronous source has no synchronous equivalent.

和 zlib.createZipArchive() 一样,这些条目由返回的迭代器拥有,不能重复使用。如果迭代提前停止——包括流条目抛出异常——导致停止的条目以及其后所有排队的条目都会被处理掉,释放它们持有的任何资源。

🌐 As with zlib.createZipArchive(), the entries are owned by the returned iterator and must not be reused. If iteration stops early - including the throw on a streaming entry - the entry that stopped it and every entry still queued behind it are disposed, releasing any sources they hold.