diff --git a/__tests__/vfs.js b/__tests__/vfs.js index ca0a76b..2eb3837 100644 --- a/__tests__/vfs.js +++ b/__tests__/vfs.js @@ -43,6 +43,12 @@ const call = (method, ...args) => VFS[method](testAdapter, testMount)(...args); const callOther = (method, ...args) => VFS[method](testAdapter, otherMount)(...args); describe('VFS', () => { + test('#capabilities', () => { + return expect(call('capabilities', 'null:/')) + .resolves + .toMatchObject({}); + }); + test('#readdir', () => { return expect(call('readdir', 'null:/')) .resolves @@ -79,7 +85,7 @@ describe('VFS', () => { .toBeInstanceOf(ArrayBuffer); }); - test('writefile - blob', () => { + test('#writefile - blob', () => { return expect(call('writefile', 'null:/filename', new Blob())) .resolves .toBe(-1); diff --git a/src/adapters/vfs/null.js b/src/adapters/vfs/null.js index ad55b42..75e111b 100644 --- a/src/adapters/vfs/null.js +++ b/src/adapters/vfs/null.js @@ -34,6 +34,7 @@ * @param {object} [options] Adapter options */ const nullAdapter = ({ + capabilities: (path, options) => Promise.resolve({}), readdir: (path, options) => Promise.resolve([]), readfile: (path, type, options) => Promise.resolve({body: new ArrayBuffer(), mime: 'application/octet-stream'}), writefile: (path, data, options) => Promise.resolve(-1), diff --git a/src/adapters/vfs/system.js b/src/adapters/vfs/system.js index bf8a388..bc803c5 100644 --- a/src/adapters/vfs/system.js +++ b/src/adapters/vfs/system.js @@ -28,7 +28,7 @@ * @license Simplified BSD License */ -const getters = ['exists', 'stat', 'readdir', 'readfile']; +const getters = ['capabilities', 'exists', 'stat', 'readdir', 'readfile']; const requester = core => (fn, body, type, options = {}) => core.request(`/vfs/${fn}`, { @@ -57,6 +57,11 @@ const methods = (core, request) => { .then(({body}) => body); return { + capabilities: ({path}, options) => request('capabilities', { + path, + options + }, 'json').then(({body}) => body), + readdir: ({path}, options) => request('readdir', { path, options, diff --git a/src/filesystem.js b/src/filesystem.js index 9bc0244..70a7324 100644 --- a/src/filesystem.js +++ b/src/filesystem.js @@ -63,6 +63,7 @@ import merge from 'deepmerge'; * Filesystem Adapter Methods * TODO: typedef * @typedef {Object} FilesystemAdapterMethods + * @property {Function} capabilities * @property {Function} readdir * @property {Function} readfile * @property {Function} writefile diff --git a/src/vfs.js b/src/vfs.js index ef9b394..fc00efa 100644 --- a/src/vfs.js +++ b/src/vfs.js @@ -73,6 +73,16 @@ const handleDirectoryList = (path, options) => result => showHiddenFiles: options.showHiddenFiles !== false, filter: options.filter })); +/** + * Get vfs capabilities + * + * @param {string|VFSFile} path The path of a file + * @param {VFSMethodOptions} [options] Options + * @return {Promise} An object of capabilities + */ +export const capabilities = (adapter, mount) => (path, options = {}) => + adapter.capabilities(pathToObject(path), options, mount); + /** * Read a directory