Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

unionfs

streamich774.8k4.5.4TypeScript support: included

Use multiple fs modules in a union.

fs, file, file system, mount, union, unionfs, many file systems, multiple

readme

unionfs

Creates a union of multiple fs file systems.

npm install --save unionfs

This module allows you to use multiple objects that have file system fs API at the same time.

import { ufs } from 'unionfs';
import { fs as fs1 } from 'memfs';
import * as fs2 from 'fs';

ufs.use(fs1).use(fs2);

ufs.readFileSync(/* ... */);

Use this module with memfs and linkfs. memfs allows you to create virtual in-memory file system. linkfs allows you to redirect fs paths.

You can also use other fs-like objects.

import * as fs from 'fs';
import { Volume } from 'memfs';
import * as MemoryFileSystem from 'memory-fs';
import { ufs } from 'unionfs';

const vol1 = Volume.fromJSON({ '/memfs-1': '1' });
const vol2 = Volume.fromJSON({ '/memfs-2': '2' });

const memoryFs = new MemoryFileSystem();
memoryFs.writeFileSync('/memory-fs', '3');

ufs.use(fs).use(vol1).use(vol2).use(memoryFs);

console.log(ufs.readFileSync('/memfs-1', 'utf8')); // 1
console.log(ufs.readFileSync('/memfs-2', 'utf8')); // 2
console.log(ufs.readFileSync('/memory-fs', 'utf8')); // 3

You can create a Union instance manually:

import { Union } from 'unionfs';

var ufs1 = new Union();
ufs1.use(fs).use(vol);

var ufs2 = new Union();
ufs2.use(fs).use(/*...*/);

License

Unlicense - public domain.

changelog

4.5.4 (2024-03-19)

Bug Fixes

  • readdir and readdirSync failing on valid empty directory if another fs fails (#787) (dab090e)

4.5.3 (2024-03-19)

Bug Fixes

  • createWriteStream and createReadStream targeting fss in wrong order (#785) (944275d)

4.5.2 (2024-03-19)

Bug Fixes

  • createWriteStream failing to create new files in directories (#783) (cc52c7f)

4.5.1 (2023-06-03)

Bug Fixes

  • actually build library before publishing (#767) (fe706ad)

4.5.0 (2023-06-02)

Features

4.4.0 (2020-03-12)

Features

  • support withFileTypes option for readdir methods (23472d7)

4.3.2 (2020-02-17)

Bug Fixes

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

4.3.1 (2020-02-15)

Bug Fixes

  • generate type definitions (0f87f53)

4.3.0 (2020-02-15)

Features

  • support promises namespace (f7bd521)

4.2.1 (2019-12-19)

Bug Fixes

  • readdir: 🐛 Error no such file or directory (8d21e9a)
  • readdirSync: 🐛 Error no such file or directory (b6c5764), closes #240

4.2.0 (2019-03-02)

Bug Fixes

Features

  • 🎸 upgrade dependecies (91635f8)

4.1.0 (2019-03-01)

Features

4.0.0 (2019-01-30)

Bug Fixes

  • deps: update dependency fs-monkey to ^0.3.0 (c19864e)

Features

  • 🎸 re-enable semantic-release (5dc0842)
  • make readdir merge results from all file systems (347d2b0)
  • refactor and improve watch() implementation (6b9a3f2)

BREAKING CHANGES

  • behaviour of watchFile() and unwatchFile() changes.
  • readdir now behaves differently

  • add implementation of readdir and readdirSync

  • tidy up code from review

  • corectly dedupe readdir for multiple fss

  • sort results from readdir