wfs-local
Minimal subset of file operations for remote services
Last updated 10 months ago by mkozhukh .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install wfs-local 
SYNC missed versions from official npm registry.

Web File System - Local files driver

npm version Build Status

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

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: a => /\.(txt|doc)/.test(a) });

//ignore some files
let files = await fs.list("/subfolder", { exclude: a => a === ".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

//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

// 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

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

License

MIT

Current Tags

  • 0.3.0                                ...           latest (10 months ago)

3 Versions

  • 0.3.0                                ...           10 months ago
  • 0.2.0                                ...           10 months ago
  • 0.1.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 5
Dependencies (2)
Dev Dependencies (8)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |