On this page

C

ZipProvider

History

A provider that exposes the entries of a ZIP archive - either a zlib.ZipBuffer (in memory) or a zlib.ZipFile (on disk) - through the VFS API. provider.readonly reflects the archive's own zipFile.writable flag: a ZipBuffer is always writable, and a ZipFile is writable only when opened with { writable: true }.

Directories are recognized both explicitly (an entry whose name ends in /) and implicitly (any entry name starting with "<dir>/"). readdir() does not support { recursive: true }. Because a ZIP member cannot be edited or read in place - only fully written or fully decompressed - a file opened for writing only commits its content (as a new archive entry) when the handle is closed.

Every method has a synchronous counterpart (openSync(), statSync(), readdirSync(), and so on), backed by the equally complete synchronous surface zlib.ZipBuffer/zlib.ZipFile expose. As with those, the synchronous methods here block the Node.js event loop and further JavaScript execution until the operation - including any deflate/inflate pass - completes.

const vfs = require('node:vfs');
const zlib = require('node:zlib');
const { readFileSync } = require('node:fs');

async function main() {
  const zip = new zlib.ZipBuffer(readFileSync('archive.zip'));
  const archiveVfs = vfs.create(new vfs.ZipProvider(zip));

  console.log(await archiveVfs.promises.readdir('/'));
  await archiveVfs.promises.writeFile('/new.txt', 'hello');
}
main();
C

ZipProvider Constructor

History
new ZipProvider(source): ZipProvider
Attributes
An already-open archive.