MCPcopy
hub / github.com/jvilk/BrowserFS / defineFcn

Function defineFcn

src/backend/MountableFileSystem.ts:355–385  ·  view source on GitHub ↗

* Tricky: Define all of the functions that merely forward arguments to the * relevant file system, or return/throw an error. * Take advantage of the fact that the *first* argument is always the path, and * the *last* is the callback function (if async). * @todo Can use numArgs to make proxying m

(name: string, isSync: boolean, numArgs: number)

Source from the content-addressed store, hash-verified

353 * @hidden
354 */
355function defineFcn(name: string, isSync: boolean, numArgs: number): (...args: any[]) => any {
356 if (isSync) {
357 return function(this: MountableFileSystem, ...args: any[]) {
358 const path = args[0];
359 const rv = this._getFs(path);
360 args[0] = rv.path;
361 try {
362 return (<any> rv.fs)[name].apply(rv.fs, args);
363 } catch (e) {
364 this.standardizeError(e, rv.path, path);
365 throw e;
366 }
367 };
368 } else {
369 return function(this: MountableFileSystem, ...args: any[]) {
370 const path = args[0];
371 const rv = this._getFs(path);
372 args[0] = rv.path;
373 if (typeof args[args.length - 1] === 'function') {
374 const cb = args[args.length - 1];
375 args[args.length - 1] = (...args: any[]) => {
376 if (args.length > 0 && args[0] instanceof ApiError) {
377 this.standardizeError(args[0], rv.path, path);
378 }
379 cb.apply(null, args);
380 };
381 }
382 return (<any> rv.fs)[name].apply(rv.fs, args);
383 };
384 }
385}
386
387/**
388 * @hidden

Callers 1

Calls 2

_getFsMethod · 0.80
standardizeErrorMethod · 0.80

Tested by

no test coverage detected