@tabcat/orbit-db-fsstore
Advanced tools
Comparing version 3.0.2 to 3.1.0
{ | ||
"name": "@tabcat/orbit-db-fsstore", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"description": "a custom orbit-db store representing a file system", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -27,3 +27,8 @@ | ||
// creates an fs with a root dir | ||
const setRoot = (fs) => fs.set('/r', { type: cTypes.dir }) | ||
const defaultRoot = '/r' | ||
const setRoot = (fs) => { | ||
fs.root = defaultRoot | ||
return fs.set(defaultRoot, { type: cTypes.dir }) | ||
} | ||
const root = (fs) => fs.root | ||
const create = (state) => setRoot(new Map(state)) | ||
@@ -51,15 +56,20 @@ | ||
const isOver = (p1, p2) => `${p1}/` === p2.slice(0, p1.length + 1) | ||
const isOneHigher = (p1, p2) => p1.split('/').length + 1 === p2.split('/').length | ||
const sortFn = (o, t) => o.toLowerCase().localeCompare(t.toLowerCase()) | ||
function tree (fs, path) { | ||
const a = [] | ||
for (const p of fs.keys()) { | ||
if (`${path}/` === p.slice(0, path.length + 1)) { | ||
a.push(p) | ||
} | ||
if (isOver(path, p)) a.push(p) | ||
} | ||
return a | ||
return a.sort(sortFn) | ||
} | ||
function ls (fs, path) { | ||
return tree(fs, path) | ||
.filter(p => path.split('/').length + 1 === p.split('/').length) | ||
const a = [] | ||
for (const p of fs.keys()) { | ||
if (isOver(path, p) && isOneHigher(path, p)) a.push(p) | ||
} | ||
return a.sort(sortFn) | ||
} | ||
@@ -202,2 +212,3 @@ | ||
ops, | ||
root, | ||
create, | ||
@@ -204,0 +215,0 @@ exists, |
@@ -72,7 +72,7 @@ | ||
this.pathName = pathName | ||
this.exists = (path = '') => fs.exists(this._index.get(), path) | ||
this.content = (path = '') => fs.content(this._index.get(), path) | ||
this.read = (path = '') => fs.read(this._index.get(), path) | ||
this.tree = (path = '') => fs.tree(this._index.get(), path) | ||
this.ls = (path = '') => fs.ls(this._index.get(), path) | ||
this.exists = (path = '') => fs.exists(this.index, path) | ||
this.content = (path = '') => fs.content(this.index, path) | ||
this.read = (path = '') => fs.read(this.index, path) | ||
this.tree = (path = '') => fs.tree(this.index, path) | ||
this.ls = (path = '') => fs.ls(this.index, path) | ||
@@ -84,2 +84,4 @@ this.paramChecks = paramChecks(this) | ||
get root () { return fs.root(this.index) } | ||
_addOp ({ op, ...payload }) { | ||
@@ -86,0 +88,0 @@ const cType = op.slice(-3) === 'DIR' ? fs.cTypes.dir : fs.cTypes.file |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16475
348