Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VFS capabilities method #186

Merged
merged 2 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}));

/**
andersevenrud marked this conversation as resolved.
Show resolved Hide resolved
* 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