Skip to content

Commit 9e72aee

Browse files
author
mahsa shadi
committed
Add VFS capabilities method
1 parent 6a8fe4d commit 9e72aee

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

__tests__/vfs.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ const call = (method, ...args) => VFS[method](testAdapter, testMount)(...args);
4343
const callOther = (method, ...args) => VFS[method](testAdapter, otherMount)(...args);
4444

4545
describe('VFS', () => {
46+
test('#capabilities', () => {
47+
return expect(call('capabilities', 'null:/'))
48+
.resolves
49+
.toMatchObject({});
50+
});
51+
4652
test('#readdir', () => {
4753
return expect(call('readdir', 'null:/'))
4854
.resolves
@@ -79,7 +85,7 @@ describe('VFS', () => {
7985
.toBeInstanceOf(ArrayBuffer);
8086
});
8187

82-
test('writefile - blob', () => {
88+
test('#writefile - blob', () => {
8389
return expect(call('writefile', 'null:/filename', new Blob()))
8490
.resolves
8591
.toBe(-1);

src/adapters/vfs/null.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* @param {object} [options] Adapter options
3535
*/
3636
const nullAdapter = ({
37+
capabilities: (path, options) => Promise.resolve({}),
3738
readdir: (path, options) => Promise.resolve([]),
3839
readfile: (path, type, options) => Promise.resolve({body: new ArrayBuffer(), mime: 'application/octet-stream'}),
3940
writefile: (path, data, options) => Promise.resolve(-1),

src/adapters/vfs/system.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* @license Simplified BSD License
2929
*/
3030

31-
const getters = ['exists', 'stat', 'readdir', 'readfile'];
31+
const getters = ['capabilities', 'exists', 'stat', 'readdir', 'readfile'];
3232

3333
const requester = core => (fn, body, type, options = {}) =>
3434
core.request(`/vfs/${fn}`, {
@@ -57,6 +57,11 @@ const methods = (core, request) => {
5757
.then(({body}) => body);
5858

5959
return {
60+
capabilities: ({path}, options) => request('capabilities', {
61+
path,
62+
options
63+
}, 'json').then(({body}) => body),
64+
6065
readdir: ({path}, options) => request('readdir', {
6166
path,
6267
options,

src/filesystem.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import merge from 'deepmerge';
6363
* Filesystem Adapter Methods
6464
* TODO: typedef
6565
* @typedef {Object} FilesystemAdapterMethods
66+
* @property {Function} capabilities
6667
* @property {Function} readdir
6768
* @property {Function} readfile
6869
* @property {Function} writefile

src/vfs.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ const handleDirectoryList = (path, options) => result =>
7373
showHiddenFiles: options.showHiddenFiles !== false,
7474
filter: options.filter
7575
}));
76+
/**
77+
* Get vfs capabilities
78+
*
79+
* @param {string|VFSFile} path The path of a file
80+
* @param {VFSMethodOptions} [options] Options
81+
* @return {Promise<object[]>} An object of capabilities
82+
*/
83+
export const capabilities = (adapter, mount) => (path, options = {}) =>
84+
adapter.capabilities(pathToObject(path), options, mount);
85+
7686

7787
/**
7888
* Read a directory

0 commit comments

Comments
 (0)