All files / src/fsa index.ts

94.11% Statements 16/17
100% Branches 2/2
50% Functions 1/2
93.75% Lines 15/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 452x             2x 2x   2x 2x 2x 2x 2x 2x 2x 2x                                   2x 9x 9x         9x    
import { CoreFileSystemDirectoryHandle } from './CoreFileSystemDirectoryHandle';
import {
  CoreFsaContext,
  IFileSystemChangeRecord,
  IFileSystemObserver,
  IFileSystemObserverConstructable,
} from './types';
import { Superblock } from '../core/Superblock';
import { CoreFileSystemObserver } from './CoreFileSystemObserver';
 
export * from './types';
export * from './CoreFileSystemHandle';
export * from './CoreFileSystemDirectoryHandle';
export * from './CoreFileSystemFileHandle';
export * from './CoreFileSystemSyncAccessHandle';
export * from './CoreFileSystemWritableFileStream';
export * from './CoreFileSystemObserver';
export * from './CorePermissionStatus';
 
/**
 * Create a new instance of an in-memory File System Access API
 * implementation rooted at the root directory of the filesystem.
 *
 * @param ctx Optional context for the File System Access API.
 * @param core Optional low-level file system implementation to
 *     back the File System Access API. If not provided, a new empty
 *     Superblock instance will be created.
 * @param dirPath Optional path within the filesystem to use as the root
 *     directory of the File System Access API. Defaults to `/`.
 * @returns A File System Access API implementation `dir` rooted at
 *     the root directory of the filesystem, as well as the `core`,
 *     a low-level file system implementation itself. Also, returns
 *     `FileSystemObserver`, a class that can be used to create
 *     observers that watch for changes to files and directories.
 */
export const fsa = (ctx?: Partial<CoreFsaContext>, core = new Superblock(), dirPath: string = '/') => {
  const dir = new CoreFileSystemDirectoryHandle(core, dirPath, ctx);
  const FileSystemObserver: IFileSystemObserverConstructable = class FileSystemObserver extends CoreFileSystemObserver {
    constructor(callback: (records: IFileSystemChangeRecord[], observer: IFileSystemObserver) => void) {
      super(core, callback);
    }
  };
  return { core, dir, FileSystemObserver };
};