nv-file-vfs-base
v1.0.24
Published
nv-file-vfs-base ============== - simple virtual file - only support 6 actions: - cd(nvpath) | touch(nvpath) | mkdir(nvpath) | - ln(linkto\_nvpath,linkfrom\_nvpath) /*softlink ln -s*/ | - rm(nvpath) | erase(nvpath) /*removed AND cant recycle*/ - n
Downloads
22
Readme
nv-file-vfs-base
simple virtual file
only support 13 actions:
rename(nvpath,name) |
rename_self(name)
cd(nvpath) |
ls(nvpath) |
tree(nvpath) |
touch(nvpath) |
mkdir(nvpath) |
ln(linkto_nvpath,linkfrom_nvpath) /softlink ln -s/ |
rm(nvpath) |
erase(nvpath) /removed AND cant recycle/ |
swap(nvpath0,nvpath1) |
mv(src_nvpath,dst_nvpath) |
cp(src_nvpath,dst_nvpath) /*cp + cp -r */
nvpath is a path format:
begin with "/" is absolute path
end with "/" is a dir
"../" means parent ; ".../" means parent-of-parent ; "..../" "...../" ....
its a simple version of nv-remote-file AND nv-browser-file
suitable for small scale datas( <= 1000000)
install
- npm install nv-file-vfs-base
usage
const {Disk,FileNode,load_disk_from_dump} = require("nv-file-vfs-base");
example
var disk = new Disk(20000);
var rt = disk.creat_root_dir()
var c = rt.mkdir("a/b/c")
var f = c.touch("e/f")
show
/*
> rt
%2d239cf3:1% {} [
└── a
└── b
└── c
└── e [...]
]
>
*/
ln -s
var Y = rt.ln("a/b/c/e","X/Y")
Y.ref_
/*
> Y.ref_
e %5da07506:5% {} [
e
└── f
]
> Y.ref_ === rt.cd("a/b/c/e")
true
>
> Y.ref_.refed_by_
Set(1) { Y -> /a/b/c/e/ }
>
> Y
Y -> /a/b/c/e/
>
*/
cd .. ... ....
var b = rt.cd("a/b")
var e = b.cd("c/e")
/*
> c.cd("/a") === rt.$fstch_
true
> c.cd("/b") === null
true
>
*/
/*
> b.cd("../")
a %def4534d:2% {} [
a
└── b
└── c
└── e
└── f
]
>
> c.cd(".../")
a %480bf36e:2% {} [
a
└── b
└── c
└── e
└── f
]
>
*/
write read
> c.write({meta:6666,data:"abcdefg"})
> c
c %5da07506:4% {
"meta": 6666,
"data": "abcdefg"
} [
c
└── e
└── f
]
> c.read()
{ meta: 6666, data: 'abcdefg' }
>
rename
var b = rt.cd("a/b")
b.rename_self("BABABA")
/*
> rt
{} [
├── a
│ └── BABABA
│ └── c
│ └── e [...]
└── X
└── Y -> /a/BABABA/c/e/
]
>
*/
rt.rename("a/BABABA/c","C2");
/*
> rt
{} [
├── a
│ └── BABABA
│ └── C2
│ └── e [...]
└── X
└── Y -> /a/BABABA/C2/e/
]
>
*/
swap
var X = rt.cd("X")
X.swap("/a/BABABA/C2")
/*
> rt
{} [
├── a
│ └── BABABA
│ └── X
│ └── Y -> /C2/e/
└── C2
└── e
└── f
]
>
*/
mv
rt.mv("C2/e","R/S/T")
/*
{} [
├── a
│ └── BABABA
│ └── X
│ └── Y -> /R/S/T/
├── C2{}
└── R
└── S
└── T
└── f
*/
cp
rt.cp("/a","/C2")
/*
{} [
├── a
│ └── BABABA
│ └── X
│ └── Y -> /R/S/T/
├── C2
│ └── a
│ └── BABABA
│ └── X [...]
└── R
└── S
└── T
└── f
*/
rt.cp("/a","E")
/*
{} [
├── a
│ └── BABABA
│ └── X
│ └── Y -> /R/S/T/
├── C2
│ └── a
│ └── BABABA
│ └── X [...]
├── R
│ └── S
│ └── T
│ └── f
└── E
└── BABABA
└── X
└── Y -> /R/S/T/
*/
soft remove (can recycle)
include external slink after remove
> rt
%dhUzhqVm:1% {} [
├── a
│ └── BABABA
│ └── X
│ └── Y -> /R/S/T/
├── C2
│ └── a
│ └── BABABA
│ └── X [...]
├── R
│ └── S
│ └── T
│ └── f
└── E
└── BABABA
└── X
└── Y -> /R/S/T/
]
> rt.rm("E")
E {} [
E
└── BABABA
└── X
└── Y -> <empty> //coz /R/S/T NOT in rmoved-subtree E, so its empty now
]
> disk.fdisk()
[
{} [
├── a
│ └── BABABA
│ └── X
│ └── Y -> /R/S/T/
├── C2
│ └── a
│ └── BABABA
│ └── X [...]
└── R
└── S
└── T
└── f
],
E {} [
E
└── BABABA
└── X
└── Y -> <empty>
]
]
>
no external slink after remove
rt.ln("R/S/T/f","R/S/m");
m -> /R/S/T/f {}
>
> rt
{} [
├── a
│ └── BABABA
│ └── X
│ └── Y -> /R/S/T/
├── C2
│ └── a
│ └── BABABA
│ └── X [...]
└── R
└── S
├── T
│ └── f
└── m -> /R/S/T/f
]
>
> rt.rm("/R/S")
S %mQAjIMWc:12% {} [
S
├── T
│ └── f
└── m -> S/T/f
]
> rt
%mQAjIMWc:1% {} [
├── a
│ └── BABABA
│ └── X
│ └── Y -> <empty> // /R/S is removed NOT in root
├── C2
│ └── a
│ └── BABABA
│ └── X [...]
└── R{}
]
> disk.fdisk()
[
%mQAjIMWc:1% {} [
├── a
│ └── BABABA
│ └── X
│ └── Y -> <empty>
├── C2
│ └── a
│ └── BABABA
│ └── X [...]
└── R{}
],
S %mQAjIMWc:12% {} [
S
├── T
│ └── f
└── m -> S/T/f // S/T/f STILL IN removed subtree SO its still HERE
],
E %mQAjIMWc:20% {} [
E
└── BABABA
└── X
└── Y -> <empty>
]
]
>
erase (cant recycle)
> rt.erase("R")
%erased% {}
>
> rt
%ZqRqpQWn:1% {} [
├── a
│ └── BABABA
│ └── X
│ └── Y -> <empty>
└── C2
└── a
└── BABABA
└── X [...]
]
> disk.fdisk() // R disappeared AND cant BE recovered
[
%ZqRqpQWn:1% {} [
├── a
│ └── BABABA
│ └── X
│ └── Y -> <empty>
└── C2
└── a
└── BABABA
└── X [...]
],
S %ZqRqpQWn:12% {} [
S
├── T
│ └── f
└── m -> S/T/f
],
E %ZqRqpQWn:20% {} [
E
└── BABABA
└── X
└── Y -> <empty>
]
]
>
Disk
> disk
Disk {
fid: 'ZqRqpQWnNKlHWiinQikVtITTfHAZRvMiligG',
max_size: 20000,
idpool: { minid_: 1, maxid_: 20000, used_: 18, lefted_: 19982 }
}
>
> disk.fdisk()
[
%ZqRqpQWn:1% {} [
├── a
│ └── BABABA
│ └── X
│ └── Y -> <empty>
└── C2
└── a
└── BABABA
└── X [...]
],
S %ZqRqpQWn:12% {} [
S
├── T
│ └── f
└── m -> S/T/f
],
E %ZqRqpQWn:20% {} [
E
└── BABABA
└── X
└── Y -> <empty>
]
]
> var dumped = disk.dump()
> var disk2 = load_disk_from_dump(dumped)
> disk2.fdisk()
[
%ZqRqpQWn:1% {} [
├── a
│ └── BABABA
│ └── X
│ └── Y -> <empty>
└── C2
└── a
└── BABABA
└── X [...]
],
S %ZqRqpQWn:12% {} [
S
├── T
│ └── f
└── m -> S/T/f
],
E %ZqRqpQWn:20% {} [
E
└── BABABA
└── X
└── Y -> <empty>
]
]
>
METHODS
###FileNode
self define read/write methods, using add_read_method add_write_method
rt.read rt.write
rt.aread rt.awrite
tag getter
rt.$_raw_tag_ //real name
rt.$tag_ //for display using
rt.nvpath_ //path string
rt.ref_ // soft-link-node point to -> ref_
rt.refed_by_ // Set , soft-link-nodes point-to self
actions
rt.rename(path,name)
rt.rename_self(name) //rename self
rt.cd(path)
rt.ls(path) // children
rt.tree(path) // des-nodes in dfs sequence
rt.mkdir(path) //path always be treated as dir
rt.touch(path) // if path ends with "/" same as mkdir ,
rt.ln(linkto_path,linkfrom_path) //
rt.rm(path) // rm + rm -r ; removed nodes can be found using disk.removed_;
rt.erase(path) // rm + rm -r ; erased nodes will disappear
rt.swap(p0,p1)
rt.mv(srcp,dstp)
rt.cp(srcp,dstp) // cp + cp -r;
node type
rt.is_dir()
rt.is_file()
rt.is_slink()
show
rt.$disable_repr() //disable struct display, improve performance(disable console.log for nodes)
rt.$enable_repr() //enable struct display
// by default show depth =4
// (cant change , coz console.log performance issue when too many nodes)
internal init using
rt.is_undef()
rt.set_as_dir()
rt.set_as_file()
rt.set_as_slink()
relations
other methods begin with $, provide ways to find sibling/parent/....
disk
disk.max_size //max_nodes when <= 1000000 will be fast.
// can only be set when new Disk(max_size)
// max_size cant change after new Disk
disk.creat_root_dir()
disk.fdisk() // list all "root-dir"
disk.removed_ // nodes be removed BUT not erased
disk.invalid_slinks_ // soft-link link-to null
APIS
new Disk(max_size) //default 10000 , if more than 1000000 , performance BAD
{
ERRORS: VFSError(5) {
'parent_node_is_not_dir',
'cant_link_dir_to',
'file_exist',
'link_to_dst_not_exist',
'not_impl'
},
add_write_method(write,awrite),
DFLT_WRITE: [Function: DFLT_WRITE],
DFLT_AWRITE: [AsyncFunction: DFLT_AWRITE],
add_read_method(read,aread),
DFLT_READ: [Function: DFLT_READ],
DFLT_AREAD: [AsyncFunction: DFLT_AREAD],
FileNode: [class FileNode extends ],
Disk: [class Disk extends Forest]
load_disk_from_dump(dumped_disk)
}
LICENSE
- ISC