breadfs
v0.1.11
Published
Unified File System Abstraction
Maintainers
Readme
BreadFS
Unified File System Abstraction.
- Frequently used file system operation API
- Operating files across different file systems
- In-Memory file system provider
- Node.js fs module provider
- WebDAV provider
- 阿里云盘 provider
import { fs as nfs } from 'breadfs/node'
import { MemFS } from 'breadfs/mem'
import { WebDAVFS } from 'breadfs/webdav'
// Write something to hello.txt
const local = nfs.path('hello.txt')
await local.writeText('This is from local file system')
// Create in-memory file system
const mfs = MemFS.make()
const mem = mfs.path('hello.txt')
await mfs.writeText('This is from in-memory')
await mfs.zip() // create zip archive
// 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 breadfsNotice
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
Installtion:
npm i breadfs @breadfs/webdavUsage:
import { WebDAVFS } from 'breadfs/webdav'
const wfs = WebDAVFS.make("https://some-server.org", {
username: "user",
password: "pass"
})
await wfs.path('/test.txt').readText()阿里云盘
Installtion:
npm i breadfs @breadfs/aliyundriveUsage:
You can follow this OpenList docs and OpenList Token 获取工具 to get the aliyundrive refresh token.
import { AliyundriveFS } from 'breadfs/aliyundrive'
const fs = new AliyundriveFS({
refresh: {
token: process.env.ALIYUNDRIVE_REFRESH_TOKEN!,
endpoint: 'https://api.oplist.org/alicloud/renewapi'
}
})
const resp = await fs.list('/anime/');
console.log(resp)Operating files 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
