Skip to content

Commit

Permalink
Add VFS capabilities method (#186)
Browse files Browse the repository at this point in the history
Co-authored-by: mahsa shadi <[email protected]>
  • Loading branch information
mahsashadi and mahsa shadi authored Aug 1, 2022
1 parent ff182bc commit 0e38221
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
8 changes: 7 additions & 1 deletion __tests__/vfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/adapters/vfs/null.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion src/adapters/vfs/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`, {
Expand Down Expand Up @@ -57,6 +57,8 @@ const methods = (core, request) => {
.then(({body}) => body);

return {
capabilities: passthrough('capabilities'),

readdir: ({path}, options) => request('readdir', {
path,
options,
Expand Down
1 change: 1 addition & 0 deletions src/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/vfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ const handleDirectoryList = (path, options) => result =>
filter: options.filter
}));

/**
* Get vfs capabilities
*
* @param {string|VFSFile} path The path of a file
* @param {VFSMethodOptions} [options] Options
* @return {Promise<object[]>} An object of capabilities
*/
export const capabilities = (adapter, mount) => (path, options = {}) =>
adapter.capabilities(pathToObject(path), options, mount);


/**
* Read a directory
*
Expand Down

0 comments on commit 0e38221

Please sign in to comment.