memfs

In-memory file-system with Node's fs API.

memfs downloads memfs version memfs license

memfs类似的npm包:

npm下载趋势

3 年
🌟 在 memfs 的 README.md 中显示实时使用量图表,只需复制下面的代码。
## Usage Trend
[![Usage Trend of memfs](https://npm-compare.com/img/npm-trend/THREE_YEARS/memfs.png)](https://npm-compare.com/memfs#timeRange=THREE_YEARS)

Cumulative GitHub Star Trend

🌟 在 memfs 的 README.md 中显示 GitHub stars 趋势图表,只需复制下面的代码。
## GitHub Stars Trend
[![GitHub Stars Trend of memfs](https://npm-compare.com/img/github-trend/memfs.png)](https://npm-compare.com/memfs)

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
memfs29,378,9432,04028.3 kB492 天前Apache-2.0

memfs的README

memfs

In-memory file system with Node.js fs API and browser File System (Access) API.

npm

Overview

memfs is a JavaScript library that implements an in-memory file system compatible with Node.js fs module and the browser File System (Access) API. Use it for testing, mocking file systems, or creating virtual file systems in both Node.js and browser environments.

Installation

npm install memfs

Quick Start

Node.js fs API

import { fs } from 'memfs';

// Write a file
fs.writeFileSync('/hello.txt', 'Hello, World!');

// Read a file
const content = fs.readFileSync('/hello.txt', 'utf-8');
console.log(content); // "Hello, World!"

// Create a directory
fs.mkdirSync('/mydir');

// List directory contents
console.log(fs.readdirSync('/')); // ['hello.txt', 'mydir']

Browser File System API

import { fsa } from 'memfs';

// Get root directory handle
const root = await fsa.getRoot();

// Create a file
const file = await root.getFileHandle('hello.txt', { create: true });
const writable = await file.createWritable();
await writable.write('Hello, World!');
await writable.close();

// Read the file
const readable = await file.getFile();
const text = await readable.text();
console.log(text); // "Hello, World!"

Features

  • Node.js fs module API compatibility
  • Browser File System (Access) API implementation
  • Adapters between fs and File System API
  • Directory snapshots and tree printing utilities
  • Works in Node.js and modern browsers
  • TypeScript support

Documentation

For detailed documentation and more examples, visit the main project page.

License

Apache 2.0