Interface FileSystemProvider

The filesystem provider defines what the editor needs to read, write, discover, and to manage files and folders. It allows extensions to serve files from remote places, like ftp-servers, and to seamlessly integrate those into the editor.

  • Note 1: The filesystem provider API works with uris and assumes hierarchical paths, e.g. foo:/my/path is a child of foo:/my/ and a parent of foo:/my/path/deeper.
  • Note 2: There is an activation event onFileSystem:<scheme> that fires when a file or folder is being accessed.
  • Note 3: The word 'file' is often used to denote all kinds of files, e.g. folders, symbolic links, and regular files.
interface FileSystemProvider {
    onDidChangeFile: Event<FileChangeEvent[]>;
    close?(fd): void | Thenable<void>;
    copy?(source, destination, options): void | Thenable<void>;
    createDirectory(uri): void | Thenable<void>;
    delete(uri, options): void | Thenable<void>;
    open?(resource, options): number | Thenable<number>;
    read?(fd, pos, data, offset, length): number | Thenable<number>;
    readDirectory(uri): [string, FileType][] | Thenable<[string, FileType][]>;
    readFile(uri): Uint8Array | Thenable<Uint8Array>;
    rename(oldUri, newUri, options): void | Thenable<void>;
    stat(uri): FileStat | Thenable<FileStat>;
    watch(uri, options): Disposable;
    write?(fd, pos, data, offset, length): number | Thenable<number>;
    writeFile(uri, content, options): void | Thenable<void>;
}

Properties

onDidChangeFile: Event<FileChangeEvent[]>

An event to signal that a resource has been created, changed, or deleted. This event should fire for resources that are being watched by clients of this provider.

Note: It is important that the metadata of the file that changed provides an updated mtime that advanced from the previous value in the stat and a correct size value. Otherwise there may be optimizations in place that will not show the change in an editor for example.

Methods

  • Copy files or folders. Implementing this function is optional but it will speedup the copy operation.

    Parameters

    • source: Uri

      The existing file.

    • destination: Uri

      The destination location.

    • options: {
          overwrite: boolean;
      }

      Defines if existing files should be overwritten.

      • overwrite: boolean

    Returns void | Thenable<void>

    Throws

    FileNotFound when source doesn't exist.

    Throws

    FileNotFound when parent of destination doesn't exist, e.g. no mkdirp-logic required.

    Throws

    FileExists when destination exists and when the overwrite option is not true.

    Throws

    NoPermissions when permissions aren't sufficient.

  • Rename a file or folder.

    Parameters

    • oldUri: Uri

      The existing file.

    • newUri: Uri

      The new location.

    • options: {
          overwrite: boolean;
      }

      Defines if existing files should be overwritten.

      • overwrite: boolean

    Returns void | Thenable<void>

    Throws

    FileNotFound when oldUri doesn't exist.

    Throws

    FileNotFound when parent of newUri doesn't exist, e.g. no mkdirp-logic required.

    Throws

    FileExists when newUri exists and when the overwrite option is not true.

    Throws

    NoPermissions when permissions aren't sufficient.

  • Subscribe to events in the file or folder denoted by uri.

    The editor will call this function for files and folders. In the latter case, the options differ from defaults, e.g. what files/folders to exclude from watching and if subfolders, sub-subfolder, etc. should be watched (recursive).

    Parameters

    • uri: Uri

      The uri of the file to be watched.

    • options: {
          excludes: string[];
          recursive: boolean;
      }

      Configures the watch.

      • excludes: string[]
      • recursive: boolean

    Returns Disposable

    A disposable that tells the provider to stop watching the uri.

  • Write data to a file, replacing its entire contents.

    Parameters

    • uri: Uri

      The uri of the file.

    • content: Uint8Array

      The new content of the file.

    • options: {
          create: boolean;
          overwrite: boolean;
      }

      Defines if missing files should or must be created.

      • create: boolean
      • overwrite: boolean

    Returns void | Thenable<void>

    Throws

    FileNotFound when uri doesn't exist and create is not set.

    Throws

    FileNotFound when the parent of uri doesn't exist and create is set, e.g. no mkdirp-logic required.

    Throws

    FileExists when uri already exists, create is set but overwrite is not set.

    Throws

    NoPermissions when permissions aren't sufficient.