Files
node/lib/vfs.js
T
Philipp Dunkel 2247054dda vfs: add ZipProvider
Add a node:vfs provider backed by a node:zlib ZIP archive - a ZipBuffer
held in memory or a ZipFile on disk - that exposes the archive's members
as a virtual filesystem tree. Directories are recognized both explicitly
(a "name/" entry) and implicitly (any entry under "name/"), and a file
opened for writing commits its content as a new archive entry when its
handle is closed. The provider is read-only unless the backing archive
is writable, and offers both asynchronous and synchronous operations.
Available as vfs.ZipProvider.

Signed-off-by: Philipp Dunkel <pip@pipobscure.com>
PR-URL: https://github.com/nodejs/node/pull/64915
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-09-02 07:27:11 +00:00

40 lines
1.3 KiB
JavaScript

'use strict';
const {
FunctionPrototypeSymbolHasInstance,
} = primordials;
const { VirtualFileSystem } = require('internal/vfs/file_system');
const { VirtualProvider } = require('internal/vfs/provider');
const { MemoryProvider } = require('internal/vfs/providers/memory');
const { RealFSProvider } = require('internal/vfs/providers/real');
const { ZipProvider } = require('internal/vfs/providers/ziparchive');
/**
* Creates a new VirtualFileSystem instance.
* @param {VirtualProvider} [provider] The provider to use (defaults to MemoryProvider)
* @param {object} [options] Configuration options
* @param {boolean} [options.moduleHooks] Whether to enable require/import hooks (default: true)
* @param {boolean} [options.virtualCwd] Whether to enable virtual working directory
* @returns {VirtualFileSystem}
*/
function create(provider, options) {
// Handle case where first arg is options (no provider)
if (provider != null &&
!FunctionPrototypeSymbolHasInstance(VirtualProvider, provider) &&
typeof provider === 'object') {
options = provider;
provider = undefined;
}
return new VirtualFileSystem(provider, options);
}
module.exports = {
create,
VirtualFileSystem,
VirtualProvider,
MemoryProvider,
RealFSProvider,
ZipProvider,
};