Skip to content

Commit

Permalink
[FEATURE] fsInterface: Add mkdir function
Browse files Browse the repository at this point in the history
When working with the UI5 adapters, it is not necessary to create
directories. Therefore it's basically a noop
  • Loading branch information
RandomByte committed Mar 18, 2019
1 parent 38ef241 commit 5bd91ac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/fsInterface.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
/**
* Wraps readers to access them like a node fs-interface.
* Wraps readers to access them through a [Node.js fs]{@link https://nodejs.org/api/fs.html} styled interface.
*
* @public
* @alias module:@ui5/fs.fsInterface
* @param {module:@ui5/fs.AbstractReader} reader Resource Reader or Collection
* @returns {Object} Object with fs-style functions <code>readFile</code>, <code>stat</code> and <code>readdir</code>
*
* @returns {Object} Object with [Node.js fs]{@link https://nodejs.org/api/fs.html} styled functions
* [<code>readFile</code>]{@link https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback},
* [<code>stat</code>]{@link https://nodejs.org/api/fs.html#fs_fs_stat_path_options_callback},
* [<code>readdir</code>]{@link https://nodejs.org/api/fs.html#fs_fs_readdir_path_options_callback} and
* [<code>mkdir</code>]{@link https://nodejs.org/api/fs.html#fs_fs_mkdir_path_options_callback}
*/
module.exports = (reader) => {
return {
Expand Down Expand Up @@ -65,6 +70,9 @@ module.exports = (reader) => {
});
callback(null, files);
}).catch(callback);
},
mkdir(path, callback) {
setTimeout(callback, 0);
}
};
};
10 changes: 10 additions & 0 deletions test/lib/fsInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,13 @@ test("fs: stat", (t) => {
const stat = promisify(fs.stat);
return assertStat(t, stat, path.join(__dirname, "..", "fixtures", "fsInterface"), "/foo.txt");
});

test("MemAdapter: mkdir", async (t) => {
const memAdapter = new MemAdapter({
virBasePath: "/"
});
const fs = fsInterface(memAdapter);
const mkdir = promisify(fs.mkdir);

await t.notThrows(mkdir("pony"), "mkdir executes successfully");
});

0 comments on commit 5bd91ac

Please sign in to comment.