Detalhes do pacote

@cowasm/memfs

sagemathinc4.5kUnlicense3.5.1

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

fs, filesystem, fs.js, memory-fs

readme (leia-me)

memfs

This is a fork of https://www.npmjs.com/package/memfs, since there's a bunch of critical bugs and missing maintenance there, which might not be a priority for that project, but are definitely a priority for me (though I'm sending PR's). Upstream memfs has nearly 12 million downloads a week, so I can see why doing these changes would be really scary there!

Things I've done here include:

  • update to newest jest, and increase maxWorkers for testing; fix an issue with one test
  • update to newest typescript and node typings
  • update target to es2020 from es5; this does make code run more efficiently and is much easier to debug if you want to directly edit node_modules
  • fix the 13 security vulnerabilities revealed by npm audit
  • upgrade prettier and switch to using the defaults
  • switch to package-lock.json instead of yarn's lock
  • fix chmodSync bug
  • fix utimesSync bug
  • fix realpathSync bug

See https://github.com/sagemathinc/memfs-js


Upstream description

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

  • Node's fs API implemented, see old API Status, missing list, missing opendir
  • Stores files in memory, in Buffers
  • Throws sameish* errors as Node.js
  • Has concept of i-nodes
  • Implements hard links
  • Implements soft links (aka symlinks, symbolic links)
  • Permissions may* be implemented in the future
  • Can be used in browser, see memfs-webpack

Install

npm install --save memfs

Usage

import { fs } from "memfs";

fs.writeFileSync("/hello.txt", "World!");
fs.readFileSync("/hello.txt", "utf8"); // World!

Create a file system from a plain JSON:

import { fs, vol } from "memfs";

const json = {
  "./README.md": "1",
  "./src/index.js": "2",
  "./node_modules/debug/index.js": "3",
};
vol.fromJSON(json, "/app");

fs.readFileSync("/app/README.md", "utf8"); // 1
vol.readFileSync("/app/src/index.js", "utf8"); // 2

Export to JSON:

vol.writeFileSync("/script.sh", "sudo rm -rf *");
vol.toJSON(); // {"/script.sh": "sudo rm -rf *"}

Use it for testing:

vol.writeFileSync("/foo", "bar");
expect(vol.toJSON()).toEqual({ "/foo": "bar" });

Create as many filesystem volumes as you need:

import { Volume } from "memfs";

const vol = Volume.fromJSON({ "/foo": "bar" });
vol.readFileSync("/foo"); // bar

const vol2 = Volume.fromJSON({ "/foo": "bar 2" });
vol2.readFileSync("/foo"); // bar 2

Use memfs together with unionfs to create one filesystem from your in-memory volumes and the real disk filesystem:

import * as fs from "fs";
import { ufs } from "unionfs";

ufs.use(fs).use(vol);

ufs.readFileSync("/foo"); // bar

Use fs-monkey to monkey-patch Node's require function:

import { patchRequire } from "fs-monkey";

vol.writeFileSync("/index.js", 'console.log("hi world")');
patchRequire(vol);
require("/index"); // hi world

Docs

See also

  • spyfs - spies on filesystem actions
  • unionfs - creates a union of multiple filesystem volumes
  • linkfs - redirects filesystem paths
  • fs-monkey - monkey-patches Node's fs module and require function
  • libfs - real filesystem (that executes UNIX system calls) implemented in JavaScript

License

Unlicense - public domain.

changelog (log de mudanças)

3.4.7 (2022-06-24)

Bug Fixes

  • dont patch getuid and getgid on process anymore (#847) (1c19e87)

3.4.6 (2022-06-18)

Bug Fixes

3.4.5 (2022-06-18)

Bug Fixes

  • throw EEXIST when opening file that already exists with 'wx' flag (#853) (8b021b3)

3.4.4 (2022-05-28)

Bug Fixes

  • allow Uint8Arrays to be passed to FsWriteStream (#842) (4398992)

3.4.3 (2022-05-17)

Bug Fixes

  • ensure js file is copied to expected place (#838) (90e2e1d)

3.4.2 (2022-05-17)

Bug Fixes

  • set closed property correct on Node 18 (#836) (d1823e1)

3.4.1 (2021-12-30)

Bug Fixes

  • recursively sync children steps to fix rename (43e8222)

3.4.0 (2021-11-24)

Features

  • support the throwIfNoEntry option (80cf803)

3.3.0 (2021-09-19)

Bug Fixes

  • 🐛 remove unused method (05b2a47)

Features

  • 🎸 add .rmSync(), .rm(), and .promises.rm() methods (2414fb6)
  • 🎸 add support for "recursive" and "force" flags in .rm() (7f6714c)

3.2.4 (2021-09-02)

Bug Fixes

  • 🐛 use globalThis defensively (eed6bbf)

3.2.3 (2021-08-31)

Bug Fixes

  • global and timers this arg in browser (1e93ab1)
  • prevent callback from triggering twice when callback throws (07e8215)
  • prevent callback from triggering twice when callback throws (6db755d), closes #542

3.2.2 (2021-04-05)

Bug Fixes

  • deps: update dependency fs-monkey to v1.0.2 (07f05db)
  • deps: update dependency fs-monkey to v1.0.3 (84346ed)

3.2.1 (2021-03-31)

Bug Fixes

  • add The Unlicense license SDPX in package.json (#594) (0e7b04b)

3.2.0 (2020-05-19)

Bug Fixes

  • 'fromJSON()' did not consider cwd when creating directories (3d6ee3b)

Features

  • support nested objects in 'fromJSON()' (f8c329c)

3.1.3 (2020-05-14)

Bug Fixes

  • deps: update dependency fs-monkey to v1.0.1 (10fc705)

3.1.2 (2020-03-12)

Bug Fixes

  • should throw EEXIST instead of EISDIR on mkdirSync('/') (f89eede)

3.1.1 (2020-02-17)

Bug Fixes

  • deps: update dependency fs-monkey to v1 (ccd1be0)

3.1.0 (2020-02-17)

Features

  • replace fast-extend with native Object.assign (934f1f3)
  • specify engines field with node constraint of >= 8.3.0 (7d3b132)

3.0.6 (2020-02-16)

Bug Fixes

  • export DirectoryJSON from index (c447a6c)

3.0.5 (2020-02-15)

Bug Fixes

  • remove space from error message (42f870a)
  • use IStore interface instead of Storage (ff82480)
  • use PathLike type from node (98a4014)

3.0.4 (2020-01-15)

Bug Fixes

  • 🐛 handle opening directories with O_DIRECTORY (acdfac8), closes #494

3.0.3 (2019-12-25)

Bug Fixes

  • rmdir: proper async functionality (cc75c56)
  • rmdir: support recursive option (1e943ae)
  • watch: suppress event-emitter warnings (1ab2dcb)

3.0.2 (2019-12-25)

Bug Fixes

  • watch: trigger change event for creation/deletion of children in a folder (b1b7884)

3.0.1 (2019-11-26)

Performance Improvements

  • ⚡️ bump fast-extend (606775b)

3.0.0 (2019-11-26)

Bug Fixes

  • 🐛 adjust definition of TCallback to accept null for error parameter (aedcbda)
  • 🐛 adjust return of Link#walk to return Link | null (1b76cb1)
  • 🐛 adjust type of children in Link to be possibly undefined (b4945c2)
  • 🐛 allow _modeToNumber to be called w/ undefined (07c0b7a)
  • 🐛 allow _modeToNumber to return undefined (3e3c992)
  • 🐛 allow assertEncoding to be called w/ undefined (e37ab9a)
  • 🐛 allow Dirent~build to accept undefined for the encoding parameter (8ca3550)
  • 🐛 allow flagsToNumber to be called w/ undefined (dbfc754)
  • 🐛 allow mkdtempBase to be called w/ undefined for encoding (f28c395)
  • 🐛 allow modeToNumber to be called w/ undefined (336821d)
  • 🐛 allow realpathBase to be called w/ undefined for encoding (e855f1c)
  • 🐛 create tryGetChild util function (b5093a1)
  • 🐛 create tryGetChildNode util function (62b5a52)
  • 🐛 define the type elements in the Volume.releasedFds array (9e21f3a)
  • 🐛 don't assign null to ._link property in FSWatcher (71569c0)
  • 🐛 don't assign null to ._steps property in FSWatcher (0e94b9c)
  • 🐛 don't assign null to .buf property in Node (00be0c2)
  • 🐛 don't assign null to .link property in File (5d01713)
  • 🐛 don't assign null to .node property in File (d06201e)
  • 🐛 don't assign null to .node property in Link (4d7f439)
  • 🐛 don't assign null to .parent property in Link (b3e60b6)
  • 🐛 don't assign null to .symlink property in Node (9bfb6f5)
  • 🐛 don't assign null to StatWatcher.prev property (fd1a253)
  • 🐛 don't assign null to StatWatcher.vol property (1540522)
  • 🐛 don't set #vol or #parent of link to null (b396f04)
  • 🐛 enable strictNullChecks (3896de7)
  • 🐛 make StatWatcher.timeoutRef property optional (d09cd03)
  • 🐛 refactor #access to be compatible w/ strictNullChecks (82ed81b)
  • 🐛 refactor #copyFileSync to be compatible w/ strictNullChecks (40f8337)
  • 🐛 refactor #createLink to be compatible w/ strictNullChecks (7d8559d)
  • 🐛 refactor #ftruncate to be compatible w/ strictNullChecks (f2ea3f1)
  • 🐛 refactor #mkdir to be compatible w/ strictNullChecks (d5d7883)
  • 🐛 refactor #mkdirp to be compatible w/ strictNullChecks (6cf0bce)
  • 🐛 refactor #mkdtempBase to be compatible w/ strictNullChecks (d935b3b)
  • 🐛 refactor #mkdtempSync to be compatible w/ strictNullChecks (7e22617)
  • 🐛 refactor #newFdNumber to be compatible w/ strictNullChecks (0bc4a15)
  • 🐛 refactor #newInoNumber to be compatible w/ strictNullChecks (e9ba56c)
  • 🐛 refactor #openFile to be compatible w/ strictNullChecks (1c4a4ba)
  • 🐛 refactor #openLink to be compatible w/ strictNullChecks (216a85f)
  • 🐛 refactor #read to be compatible w/ strictNullChecks (87b587f)
  • 🐛 refactor #readdirBase to be compatible w/ strictNullChecks (ab248b4)
  • 🐛 refactor #readFileBase to be compatible w/ strictNullChecks (27a4dad)
  • 🐛 refactor #readlinkBase to be compatible w/ strictNullChecks (b2e0f76)
  • 🐛 refactor #resolveSymlinks to be compatible w/ strictNullChecks (6dc4913)
  • 🐛 refactor #statBase to be compatible w/ strictNullChecks (ba0c20a)
  • 🐛 refactor #symlink to be compatible w/ strictNullChecks (4148ad3)
  • 🐛 refactor #truncate to be compatible w/ strictNullChecks (fadbd77)
  • 🐛 refactor #watch to be compatible w/ strictNullChecks (415a186)
  • 🐛 refactor #watchFile to be compatible w/ strictNullChecks (2c02287)
  • 🐛 refactor #write to be compatible w/ strictNullChecks (2ba6e0f)
  • 🐛 refactor #writeFile to be compatible w/ strictNullChecks (ac78c50)
  • 🐛 refactor #writeFileBase to be compatible w/ strictNullChecks (e931778)
  • 🐛 refactor #writeSync to be compatible w/ strictNullChecks (7b67eea)
  • 🐛 refactor copyFile tests to be compatible w/ strictNullChecks (e318af2)
  • 🐛 refactor errors to be compatible w/ strictNullChecks (b25c035)
  • 🐛 refactor exists tests to be compatible w/ strictNullChecks (81a564f)
  • 🐛 refactor renameSync tests to use tryGetChildNode (8cd782a)
  • 🐛 refactor volume tests to be compatible w/ strictNullChecks (f02fbac)
  • 🐛 refactor volume tests to use tryGetChild (5a6624f)
  • 🐛 refactor volume tests to use tryGetChildNode (34acaac)
  • 🐛 refactor writeFileSync tests to be compatible w/ strictNullChecks (4b7f164)
  • 🐛 remove unused getArgAndCb function (f8bb0f8)
  • 🐛 replace throwError fn w/ inline throw createError() calls (c9a0fd6)

Features

  • 🎸 enable TypeScript strict null checks (1998b24)

BREAKING CHANGES

  • TypeScript strict null checks are now enabled which may break some TypeScript users.

2.17.1 (2019-11-26)

Bug Fixes

  • set-up semantic-release packages (0554c7e)

2.15.5 (2019-07-16)

Bug Fixes

2.15.4 (2019-06-01)

Bug Fixes

  • 🐛 accept null as value in fromJSON functions (9e1af7d)
  • 🐛 annotate return type of toJSON functions (6609840)

2.15.3 (2019-06-01)

Bug Fixes

  • 🐛 mocks process.emitWarning for browser compatibility (e3456b2), closes #374

2.15.2 (2019-02-16)

Bug Fixes

  • 🐛 BigInt type handling (c640f25)

2.15.1 (2019-02-09)

Bug Fixes

  • 🐛 show directory path when throwing EISDIR in mkdir (9dc7007)
  • 🐛 throw when creating root directory (f77fa8b), closes #325

2.15.0 (2019-01-27)

Features

  • volume: add env variable to suppress fs.promise api warnings (e6b6d0a)

2.14.2 (2018-12-11)

Bug Fixes

  • fds to start from 0x7fffffff instead of 0xffffffff (#277) (31e44ba)

2.14.1 (2018-11-29)

Bug Fixes

  • don't copy legacy files into dist (ab8ffbb), closes #263

2.14.0 (2018-11-12)

Features

  • add bigint option support (00a017e)

2.13.1 (2018-11-11)

Bug Fixes

  • 🐛 don't install semantic-release, incompat with old Node (cd2b69c)