|
1 | 1 | import { CoreFileSystemDirectoryHandle } from './CoreFileSystemDirectoryHandle';
|
2 |
| -import { CoreFsaContext } from './types'; |
| 2 | +import { CoreFsaContext, IFileSystemChangeRecord, IFileSystemObserver, IFileSystemObserverConstructable } from './types'; |
3 | 3 | import { Superblock } from '../core/Superblock';
|
| 4 | +import { CoreFileSystemObserver } from './CoreFileSystemObserver'; |
4 | 5 |
|
5 | 6 | export * from './types';
|
6 | 7 | export * from './CoreFileSystemHandle';
|
7 | 8 | export * from './CoreFileSystemDirectoryHandle';
|
8 | 9 | export * from './CoreFileSystemFileHandle';
|
9 | 10 | export * from './CoreFileSystemSyncAccessHandle';
|
10 | 11 | export * from './CoreFileSystemWritableFileStream';
|
| 12 | +export * from './CoreFileSystemObserver'; |
11 | 13 | export * from './CorePermissionStatus';
|
12 | 14 |
|
13 |
| -/** |
14 |
| - * Creates a File System Access API implementation on top of a Superblock. |
15 |
| - */ |
16 |
| -export const coreToFsa = ( |
17 |
| - core: Superblock, |
18 |
| - dirPath: string = '/', |
19 |
| - ctx?: Partial<CoreFsaContext>, |
20 |
| -): CoreFileSystemDirectoryHandle => { |
21 |
| - return new CoreFileSystemDirectoryHandle(core, dirPath, ctx); |
22 |
| -}; |
23 |
| - |
24 | 15 | /**
|
25 | 16 | * Create a new instance of an in-memory File System Access API
|
26 | 17 | * implementation rooted at the root directory of the filesystem.
|
27 | 18 | *
|
28 | 19 | * @param ctx Optional context for the File System Access API.
|
| 20 | + * @param core Optional low-level file system implementation to |
| 21 | + * back the File System Access API. If not provided, a new empty |
| 22 | + * Superblock instance will be created. |
| 23 | + * @param dirPath Optional path within the filesystem to use as the root |
| 24 | + * directory of the File System Access API. Defaults to `/`. |
29 | 25 | * @returns A File System Access API implementation `dir` rooted at
|
30 |
| - * the root directory of the filesystem, as well as the `core` |
31 |
| - * file system itself. |
| 26 | + * the root directory of the filesystem, as well as the `core`, |
| 27 | + * a low-level file system implementation itself. Also, returns |
| 28 | + * `FileSystemObserver`, a class that can be used to create |
| 29 | + * observers that watch for changes to files and directories. |
32 | 30 | */
|
33 |
| -export const fsa = (ctx?: Partial<CoreFsaContext>) => { |
34 |
| - const core = new Superblock(); |
35 |
| - const dir = new CoreFileSystemDirectoryHandle(core, '/', ctx); |
36 |
| - return { dir, core }; |
| 31 | +export const fsa = (ctx?: Partial<CoreFsaContext>, core = new Superblock(), dirPath: string = '/') => { |
| 32 | + const dir = new CoreFileSystemDirectoryHandle(core, dirPath, ctx); |
| 33 | + const FileSystemObserver: IFileSystemObserverConstructable = class FileSystemObserver extends CoreFileSystemObserver { |
| 34 | + constructor (callback: (records: IFileSystemChangeRecord[], observer: IFileSystemObserver) => void) { |
| 35 | + super(core, callback); |
| 36 | + } |
| 37 | + } |
| 38 | + return { core, dir, FileSystemObserver }; |
37 | 39 | };
|
0 commit comments