-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathworker.ts
53 lines (49 loc) · 1.26 KB
/
worker.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { expose } from 'comlink';
import { BaseShellWorker, IFileSystem } from '@jupyterlite/cockle';
import {
ContentsAPI,
DriveFS,
ServiceWorkerContentsAPI
} from '@jupyterlite/contents';
/**
* Custom DriveFS implementation using the service worker.
*/
class MyDriveFS extends DriveFS {
createAPI(options: DriveFS.IOptions): ContentsAPI {
return new ServiceWorkerContentsAPI(
options.baseUrl,
options.driveName,
options.mountpoint,
options.FS,
options.ERRNO_CODES
);
}
}
/**
* Shell web worker that uses DriveFS via service worker.
* Note that this is not exported as it is accessed from Shell via the filename.
*/
class ShellWorker extends BaseShellWorker {
/**
* Initialize the DriveFS to mount an external file system.
*/
protected override initDriveFS(
driveFsBaseUrl: string,
mountpoint: string,
fileSystem: IFileSystem
): void {
console.log('Terminal initDriveFS', driveFsBaseUrl, mountpoint);
const { FS, ERRNO_CODES, PATH } = fileSystem;
const driveFS = new MyDriveFS({
FS,
PATH,
ERRNO_CODES,
baseUrl: driveFsBaseUrl,
driveName: '',
mountpoint
});
FS.mount(driveFS, {}, mountpoint);
}
}
const worker = new ShellWorker();
expose(worker);