Skip to content

Commit 0e38221

Browse files
mahsashadimahsa shadi
andauthored
Add VFS capabilities method (#186)
Co-authored-by: mahsa shadi <[email protected]>
1 parent ff182bc commit 0e38221

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-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: 3 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,8 @@ const methods = (core, request) => {
5757
.then(({body}) => body);
5858

5959
return {
60+
capabilities: passthrough('capabilities'),
61+
6062
readdir: ({path}, options) => request('readdir', {
6163
path,
6264
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ const handleDirectoryList = (path, options) => result =>
7474
filter: options.filter
7575
}));
7676

77+
/**
78+
* Get vfs capabilities
79+
*
80+
* @param {string|VFSFile} path The path of a file
81+
* @param {VFSMethodOptions} [options] Options
82+
* @return {Promise<object[]>} An object of capabilities
83+
*/
84+
export const capabilities = (adapter, mount) => (path, options = {}) =>
85+
adapter.capabilities(pathToObject(path), options, mount);
86+
87+
7788
/**
7889
* Read a directory
7990
*

0 commit comments

Comments
 (0)