breadfs
v0.1.8
Published
Unified File System Abstraction
Downloads
224
Maintainers
Readme
BreadFS
Unified File System Abstraction.
- Frequently used file system operation API
- Operate files cross across different file systems
- Node.js fs module provider
- WebDAV client provider
import { fs as nfs } from 'breadfs/node'
import { WebDAVFS } from 'breadfs/webdav'
// Write something to hello.txt
const local = nfs.path('hello.txt')
await local.writeText('This is used for testing')
// Create WebDAV file system
const wfs = WebDAVFS.make("https://some-server.org", {
username: "user",
password: "pass"
})
// Copy the local hello.txt to the remote WebDAV server
const remote = wfs.path('/hello.txt')
await local.copyTo(remote)
await remote.readText()
// Return 'This is used for testing'
Installation
npm i breadfs
Notice
This package is built on the web native Streams API. You should add
"lib": ["ES2018", "DOM"]
to yourtsconfig.json
.
Usage
Node
import { fs as nfs } from 'breadfs/node'
const bin = nfs.path('/bin')
await bin.list()
await bin.join('node').stat()
await nfs.path('/home/.bashrc').readFile()
await nfs.path('/home/.bashrc').readText()
await nfs.path('/home/test.txt').writeText('This is used for testing')
WebDAV
npm i breadfs @breadfs/webdav
import { WebDAVFS } from 'breadfs/webdav'
const wfs = WebDAVFS.make("https://some-server.org", {
username: "user",
password: "pass"
})
await wfs.path('/test.txt').readText()
Across different file systems
import { fs as nfs } from 'breadfs/node'
import { WebDAVFS } from 'breadfs/webdav'
const wfs = WebDAVFS.make("https://some-server.org", {
username: "user",
password: "pass"
})
const local = nfs.path('hello.txt')
const remote = wfs.path('/hello.txt')
await local.writeText('This is used for testing')
await local.copyTo(remote)
await remote.readText() // 'This is used for testing'
Operating files across various different file systems can be quite challenging, which means our implementation may not function perfectly in all scenarios. Even file system in your local machine may encounter some bugs.
So that the goal of this package is to provide a straightforward abstraction and utility for use in less complex or basic situations.
Related
This package is used to power AnimeSpace, offering a comprehensive solution for automatically following bangumis. It can fetch anime resources, download desired video content, and upload them to the local file system or remote WebDAV server. The upload process is facilitated by this package.
License
MIT License © 2023 XLor