zlib.zipFiles(files, options?): stream.Readable
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.
Iterable[sourcePath, entryName] string pairs. Any iterable
works — an array, a Map, the result of Object.entries(), a generator.stream.ReadableBuffer chunks making up the serialized
archive.Builds an archive from files on disk. For each [sourcePath, entryName] pair
it reads sourcePath and adds an entry named entryName, capturing the file's
Unix mode and modification time. A directory becomes a directory entry; a
regular file's contents are streamed in (as a zlib.ZipEntry.createStream()
entry) without being buffered in memory. Directory contents are not walked
recursively — list each path you want included.
When followSymlinks is true (the default) a symbolic link is resolved and
archived as its target file; when it is false the link itself is stored as a
symbolic-link entry whose content is the target path (see
zlib.ZipEntry.createSymlink()).
import { zipFiles } from 'node:zlib'; import { createWriteStream } from 'node:fs'; import { pipeline } from 'node:stream/promises'; await pipeline( zipFiles([ ['/data/report.pdf', 'report.pdf'], ['/data/notes.txt', 'docs/notes.txt'], ]), createWriteStream('archive.zip'), );