# wfs-local

> Minimal subset of file operations for remote services

Latest version **1.1.0** (published 2025-04-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install wfs-local
pnpm add wfs-local
yarn add wfs-local
bun add wfs-local
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2025-04-03 |
| First published | 2018-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 57.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Maksim Kozhukh |
| Maintainers | mkozhukh |
| Keywords | filesystem, http |

## Links

- npm: https://www.npmjs.com/package/wfs-local
- Repository: https://github.com/xbsoftware/node-wfs-local
- Homepage: https://github.com/xbsoftware/node-wfs-local#readme
- Issues: https://github.com/xbsoftware/node-wfs-local/issues
- npm.io page: https://npm.io/package/wfs-local

## Dependencies (2)

- [fs-extra](https://npm.io/package/fs-extra.md) ^7.0.1
- [@types/fs-extra](https://npm.io/package/@types/fs-extra.md) ^5.0.4

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.1.0 (latest) — 2025-04-03
- 1.0.0 — 2020-03-18
- 0.3.0 — 2019-01-23
- 0.2.0 — 2019-01-23
- 0.1.0 — 2018-12-19

## README

Web File System - Local files driver
=========

[![npm version](https://badge.fury.io/js/wfs-local.svg)](https://badge.fury.io/js/wfs-local) 

File system abstraction with access management.

API provides common file operations for some folder on local drive. Any operations outside of the folder will be blocked. Also, it possible to configure a custom policy for read/write operations.


Can be used as backend for Webix File Manager https://webix.com/filemanager


## API

### Get data

```js
const wfs = require("wfs-local");
const fs = new wfs.LocalFiles("/temp/folder");

// get files in a folder
let files = await fs.list("/subfolder");

// get files in a folder and subfolders as plain list
let files = await fs.list("/subfolder", { subFolders: true });

// get files in a folder and subfolders as nested structure
let files = await fs.list("/subfolder", { subFolders: true, nested:true });

// get folder only
let files = await fs.list("/subfolder", { skipFiles: true });

// get files that match a mask
let files = await fs.list("/subfolder", { include: file => file.value.includes("name")});

// get files with specific types
let files = await fs.list("/subfolder", { include: file => ["txt","doc"].includes(file.type) });

// get files created on or after January 1, 2025
let files = await fs.list("/subfolder", { include: file => new Date(file.date) >= new Date("2025-01-01")});

// get files smaller than 1 MB
let files = await fs.list("/subfolder", { include: file => file.size < 1024*1024});

// ignore some files
let files = await fs.list("/subfolder", { exclude: file => file.value === ".git" });

// get info about a single file
let info = await fs.info("some.txt");

// check if file exists
let check = await fs.exists("some.txt");
```

### Modify files

```js
// make folder
await fs.mkdir("sub2");

// remove
await fs.remove("some.txt");

// copy
await fs.copy("some.txt", "/sub/");

// move
await fs.copy("some.txt", "some-data.txt");

// read
let stream = await fs.read("some.txt");

// write
await fs.write("some.txt", stream)
```

### Access Policy

```js
// ForceRoot policy is added automatically

// readonly
const wfs = require("wfs-local");
const fs = new wfs.LocalFiles("/temp/folder", new wfs.policies.ReadOnlyPolicy());

// custom
const fs = new wfs.LocalFiles("/temp/folder", {
    comply: (path, op) => {
        if (op == wfs.Operation.Read) return true;
        // write to temp folder only
        if (file.indexOf("/path/") === 0) return true;

        return false;
    }
});
```

### Other API

```js
// logging
const wfs = require("wfs-local");
const fs = new wfs.LocalFiles("/temp/folder", null, { verbose: true });
```


## License 

MIT

---
_Source: https://npm.io/package/wfs-local · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
