Skip to content

Commit

Permalink
Add mode to directoryOpen().
Browse files Browse the repository at this point in the history
Fixes #120
  • Loading branch information
tomayac committed Jul 11, 2022
1 parent f822328 commit 1c639b1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
4 changes: 4 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ export type WellKnownDirectory =
| 'pictures'
| 'videos';

export type FileSystemPermissionMode = 'read' | 'readwrite';

/**
* Saves a file to disk.
* @returns Optional file handle to save in place.
Expand Down Expand Up @@ -166,6 +168,8 @@ export function directoryOpen(options?: {
startIn?: WellKnownDirectory | FileSystemHandle;
/** By specifying an ID, the user agent can remember different directories for different IDs. */
id?: string;
/** By specifying a mode of `'readwrite'`, you can open a directory with write access. */
mode?: FileSystemPermissionMode;
/** Callback to determine whether a directory should be entered, return `true` to skip. */
skipDirectory?: (
entry: FileSystemDirectoryEntry | FileSystemDirectoryHandle
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "browser-fs-access",
"version": "0.30.2",
"version": "0.31.0",
"description": "File System Access API with legacy fallback in the browser.",
"type": "module",
"source": "./src/index.js",
Expand Down Expand Up @@ -49,7 +49,7 @@
},
"homepage": "https://github.com/GoogleChromeLabs/browser-fs-access#readme",
"devDependencies": {
"eslint": "^8.18.0",
"eslint": "^8.19.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^8.5.0",
"http-server": "^14.1.1",
Expand Down
2 changes: 2 additions & 0 deletions src/fs-access/directory-open.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ const getFiles = async (
*/
export default async (options = {}) => {
options.recursive = options.recursive || false;
options.mode = options.mode || 'read';
const handle = await window.showDirectoryPicker({
id: options.id,
startIn: options.startIn,
mode: options.mode,
});
return getFiles(handle, options.recursive, undefined, options.skipDirectory);
};

0 comments on commit 1c639b1

Please sign in to comment.