| 192 | * Mounts an Emscripten file system into the BrowserFS file system. |
| 193 | */ |
| 194 | export default class EmscriptenFileSystem extends SynchronousFileSystem { |
| 195 | public static readonly Name = "EmscriptenFileSystem"; |
| 196 | |
| 197 | public static readonly Options: FileSystemOptions = { |
| 198 | FS: { |
| 199 | type: "object", |
| 200 | description: "The Emscripten file system to use (the `FS` variable)" |
| 201 | } |
| 202 | }; |
| 203 | |
| 204 | /** |
| 205 | * Create an EmscriptenFileSystem instance with the given options. |
| 206 | */ |
| 207 | public static Create(opts: EmscriptenFileSystemOptions, cb: BFSCallback<EmscriptenFileSystem>): void { |
| 208 | cb(null, new EmscriptenFileSystem(opts.FS)); |
| 209 | } |
| 210 | public static isAvailable(): boolean { return true; } |
| 211 | |
| 212 | private _FS: any; |
| 213 | |
| 214 | /** |
| 215 | * Creates a BrowserFS file system for the given Emscripten file system. |
| 216 | * @param _FS The Emscripten file system (`FS`). |
| 217 | */ |
| 218 | constructor(_FS: any) { |
| 219 | super(); |
| 220 | this._FS = _FS; |
| 221 | } |
| 222 | public getName(): string { return this._FS.DB_NAME(); } |
| 223 | public isReadOnly(): boolean { return false; } |
| 224 | public supportsLinks(): boolean { return true; } |
| 225 | public supportsProps(): boolean { return true; } |
| 226 | public supportsSynch(): boolean { return true; } |
| 227 | |
| 228 | public renameSync(oldPath: string, newPath: string): void { |
| 229 | try { |
| 230 | this._FS.rename(oldPath, newPath); |
| 231 | } catch (e) { |
| 232 | if (e.errno === ErrorCode.ENOENT) { |
| 233 | throw convertError(e, this.existsSync(oldPath) ? newPath : oldPath); |
| 234 | } else { |
| 235 | throw convertError(e); |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | public statSync(p: string, isLstat: boolean): Stats { |
| 241 | try { |
| 242 | const stats = isLstat ? this._FS.lstat(p) : this._FS.stat(p); |
| 243 | const itemType = this.modeToFileType(stats.mode); |
| 244 | return new Stats( |
| 245 | itemType, |
| 246 | stats.size, |
| 247 | stats.mode, |
| 248 | stats.atime, |
| 249 | stats.mtime, |
| 250 | stats.ctime |
| 251 | ); |
nothing calls this directly
no outgoing calls
no test coverage detected