-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { AsyncStore } from 'zarr/types/storage/types'; | ||
import { KeyError } from 'zarr'; | ||
|
||
async function getFileHandle(root: FileSystemDirectoryHandle, key: string) { | ||
const dirs = key.split('/'); | ||
const fname = dirs.pop()!; | ||
for (const dir of dirs) { | ||
root = await root.getDirectoryHandle(dir); | ||
} | ||
return root.getFileHandle(fname); | ||
} | ||
|
||
export class FileSystemStore implements AsyncStore<ArrayBuffer> { | ||
constructor(public root: FileSystemDirectoryHandle) {} | ||
|
||
static async fromDirectoryPicker() { | ||
return new FileSystemStore(await window.showDirectoryPicker()); | ||
} | ||
|
||
async getItem(key: string) { | ||
const fileHandle = await getFileHandle(this.root, key).catch((_) => { | ||
throw new KeyError(key); | ||
}); | ||
const file = await fileHandle.getFile(); | ||
return file.arrayBuffer(); | ||
} | ||
|
||
containsItem(key: string) { | ||
return getFileHandle(this.root, key) | ||
.then((_) => true) | ||
.catch((_) => false); | ||
} | ||
|
||
keys() { | ||
return Promise.resolve([]); | ||
} | ||
|
||
deleteItem(key: string): never { | ||
throw new Error('deleteItem not implemented'); | ||
} | ||
|
||
setItem(key: string, value: ArrayBuffer): never { | ||
throw new Error('setItem not implemented'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters