npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vfilesys

v1.2.5

Published

A lightweight package for manipulating an in-memory unix-like virtual file systems (vfs).

Downloads

6

Readme

VFileSys

A lightweight package for manipulating an in-memory unix-like virtual file systems (vfs).

Install

npm install vfilesys

Usage

Requiring the module:

const VirtualFileSystem = require('vfilesys')

Initializing a new VFS:

const vfs = new VirtualFileSystem()

Creating files:

vfs.write('/some/file.txt', 'My data')

Exporting a generated VFS:

vfs.export('./somewhere/backup.json', 'json')

Importing a previously created VFS:

vfs.import('./somewhere/other-backup.json')

Creating a virtual copy of a real directory:

vfs.virtualize('./somewhere/')

API Reference:

vfs.exists(path)

vfs.exists(path: string): boolean

Verifies the existence of a file under the selected virtual file system.

vfs.isFile(path)

vfs.isFile(path: string): boolean

Verifies whether an item in the virtual file system exists and is a file.

vfs.isDirectory(path)

vfs.isDirectory(path: string): boolean

Verifies whether an item in the virtual file system exists and is a directory.

vfs.isEmptyDirectory(path)

vfs.isEmptyDirectory(path: string): boolean

Verifies whether an item in the virtual file system exists and is an empty directory.

vfs.read(path, encoding)

vfs.read(path: string, encoding?: string): buffer|string

Reads a file and returns its contents. If 'encoding' is not specified, returns data as a buffer.

vfs.stats(path)

vfs.stats(path: string): StatusObject

Returns the an instance of StatusObject from a file.

vfs.write(path, data)

vfs.write(path: string, data?: string|buffer): <VirtualFileSystem>

Writes data to a vfs file, and returns the vfs instance for method chaining.

vfs.append(path, data)

vfs.append(path: string, data?: string|buffer): <VirtualFileSystem>

Appends data to a vfs file, and returns the vfs instance for method chaining.

vfs.remove(path)

vfs.remove(path: string): <VirtualFileSystem>

Removes a file, and returns the vfs instance for method chaining.

vfs.readdir(path [, options])

vfs.readdir(path: string, [options: object]): array

Options include:

  • recurse: boolean (default: false)
    • If set to true, returns a list of all items, including subdirectories and files on them
  • absolutePaths: boolean (default: true)
    • If set to false, return relative paths to the called path
  • withFileTypes: boolean (default: false)
    • If set to true return VirtualFileSystem.VDirent object instead of filenames

vfs.listdir(path)

vfs.listdir(path: string): array

Reads and returns the contents of a directory and subdirectories. (Behaves similar to vfs.readdir with option 'recurse' enabled.

vfs.mkdir(path)

vfs.mkdir(path: string): <VirtualFileSystem>

Creates a directory (filling path gaps) and returns the vfs instance for method chaining.

vfs.rmdir(path [, force])

vfs.rmdir(path: string, [force: boolean]: <VirtualFileSystem>

Removes a directory. To remove a filled directory and its items, 'force' must be enabled.

vfs.copy(path, newpath)

vfs.copy(path: string, newpath: string): <VirtualFileSystem>

Copies a file instance from one place to another, keeping status.

vfs.move(path, newpath)

vfs.move(path: string, newpath: string): <VirtualFileSystem>

Moves a file instance from one place to another, keeping status, UUID, and creation time.

vfs.virtualize(rpath, vpath [, options])

vfs.virtualize('C:\\Users\\someone\\somewhere', '/virtualized')

Takes a real path as rpath and creates a virtualized copy of its contents in vfs under the specified vpath location.

Options include:

  • recurse: boolean (default: true)
    • If enabled, and rpath points to a directory, subcontents will be copied.
  • copyctime: boolean (default: false)
    • If enabled, causes creation time of files to be copied into the virtual envirsonment.

vfs.export(file [, exportType])

vfs.export(file: string, exportType: string('json' | 'pop')): string

Exports a JSON or POP representation of the virtual file system and also returns it.

If file is set to null, the exported version will not be saved, only returned.

The exportType parameter must be one of 'json' or 'pop', and controls the output format.

The 'pop' export format stands for 'filesystem population format', and is a minimal representation of a vfs, containing only filename and contents of entries. While, the 'json' export format includes all data of each file entry, including path, data, uuid, and ctime.

vfs.import(file)

vfs.import(file: string): <VirtualFileSystem>

Imports a previously exported JSON representation of a virtual file system into the current vfs. Conflicting entries will be overriden by the newly imported version. This method can only import instances exported with vfs.export in 'JSON' mode. For importing 'pop' files, see vfs.build documentation.

vfs.build(file)

vfs.build(file: string): <VirtualFileSystem>

Imports a previously exported POP representation of a virtual file system into the current vfs. Conflicting entries will be overriden by the newly imported version. This method can only import instances exported with vfs.export in 'POP' mode. For importing 'JSON' files, see vfs.import documentation.

As 'pop' exports of vfs instances contain minimal information, the ctime and uuid of files is not kept, and will be recreated.