Common file system interface for future file systems implementations. In order to achieve this, any file system will have to implement the Interface and transform their data output in order to match function's signatures.

The following interfaces are used in order to create a common return type for most of the calls.

class DemoFileSystem implements IFileSystem {
createDir(directoryPath: string, dirMode: number): Promise<void> {
// ... implement call
}
createFile(directoryPath: string,fileHash: SHA256Hash<BLOB>,fileName: string,fileMode: number): Promise<void> {
// ... implement call
}
readDir(dirPath: string): Promise<FileSystemDirectory> {
// ... implement call
}
readFile(filePath: string): Promise<FileSystemFile> {
// ... implement call
}
readlink(filePath: string): Promise<FileSystemFile> {
// ... implement call
}
readFileInChunks(filePath: string, length: number, position: number): Promise<FileSystemFile> {
// ... implement call
}
supportsChunkedReading(path?: string): boolean {
// ... implement call
}
stat(path: string): Promise<FileDescription> {
// ... implement call
}
rmdir(pathName: string): Promise<number> {
// ... implement call
}
unlink(pathName: string): Promise<number> {
// ... implement call
}
symlink(src: string, dest: string): Promise<void> {
// ... implement call
}
symlink(src: string, dest: string): Promise<void> {
// ... implement call
}
rename(src: string, dest: string): Promise<number> {
// ... implement call
}
chmod(pathName: string, mode: number): Promise<number> {
// ... implement call
}
}
interface IFileSystem {
    chmod(pathName: string, mode: number): Promise<number>;
    createDir(directoryPath: string, dirMode: number): Promise<void>;
    createFile(directoryPath: string, fileHash: SHA256Hash<BLOB>, fileName: string, fileMode: number): Promise<void>;
    readDir(dirPath: string): Promise<FileSystemDirectory>;
    readFile(filePath: string): Promise<FileSystemFile>;
    readFileInChunks(filePath: string, length: number, position: number): Promise<FileSystemFile>;
    readlink(filePath: string): Promise<FileSystemFile>;
    rename(src: string, dest: string): Promise<number>;
    rmdir(pathName: string): Promise<number>;
    stat(path: string): Promise<FileDescription>;
    supportsChunkedReading(path?: string): boolean;
    symlink(src: string, dest: string): Promise<void>;
    unlink(pathName: string): Promise<number>;
}

Implemented by

Methods

  • Change the permissions.

    Can throw:

    • FS_ERRORS.FSE-ENOENT when the parent dir does not exist or the given mode is not a file type
    • FS_ERRORS.FSE-EACCES-W if the parent directory does not have write permission

    Parameters

    • pathName: string

      The file path

    • mode: number

      The desired mode

    Returns Promise<number>

    • Returns 0 for success
  • Creates a directory.

    Can throw:

    • FS_ERRORS.FSE-ENOENT when the parent dir does not exist or the given mode is not a dir type
    • FS_ERRORS.FSE-EXISTS when the current path already exists
    • FS_ERRORS.FSE-EACCES-W if the parent directory does not have write permission

    Parameters

    • directoryPath: string

      The wanted dir path

    • dirMode: number

      The wanted mode for the wanted dir

    Returns Promise<void>

  • Creates a file otherwise

    Can throw:

    • FS_ERRORS.FSE-ENOENT when the parent dir does not exist or the given mode is not a file type
    • FS_ERRORS.FSE-EXISTS when the current path already exists
    • FS_ERRORS.FSE-EACCES-W if the parent directory does not have write permission

    Parameters

    • directoryPath: string

      The directory where the file will be saved

    • fileHash: SHA256Hash<BLOB>

      The BLOB file hash

    • fileName: string

      The file name

    • fileMode: number

      The file mode

    Returns Promise<void>

  • Reads a directory.

    Can throw:

    • FS_ERRORS.FSE-ENOENT if the directory does not exist
    • FS_ERRORS.FSE-EACCES-R if the directory does not have read permission

    Parameters

    • dirPath: string

      The directory path

    Returns Promise<FileSystemDirectory>

    • The content of the directory
  • Reads a file.

    Can throw:

    • FS_ERRORS.FSE-ENOENT if the file does not exist
    • FS_ERRORS.FSE-EACCES-R if the file does not have read permission

    Parameters

    • filePath: string

      The file path

    Returns Promise<FileSystemFile>

    • The content of the file
  • Reads a file in chunks by a given len and position.

    Can throw:

    • FS_ERRORS.FSE-CHUNK-R if the platform does not support chunked reading. This is supported only on Node. This happen if the check for Platform is not nodejs.
    • FS_ERRORS.FSE-ENOENT if the file does not exist
    • FS_ERRORS.FSE-EACCES-R if the file does not have read permission

    Parameters

    • filePath: string

      The file path

    • length: number
    • position: number

    Returns Promise<FileSystemFile>

    • The content of the file
  • Reads a link.

    Can throw:

    • FS_ERRORS.FSE-ENOENT if the file does not exist
    • FS_ERRORS.FSE-EACCES-R if the file does not have read permission

    Parameters

    • filePath: string

      The file path

    Returns Promise<FileSystemFile>

    • The content of the file
  • Rename file.

    Can throw:

    • FS_ERRORS.FSE-ENOENT when the parent dir does not exist or the given mode is not a file type
    • FS_ERRORS.FSE-EACCES-W if the parent directory does not have write permission

    Parameters

    • src: string

      The src path

    • dest: string

      The dest path

    Returns Promise<number>

    • Returns 0 for success
  • Deletes a directory

    Can throw:

    • FS_ERRORS.FSE-ENOENT if the dir does not exist
    • FS_ERRORS.FSE-EACCES-W if the dir does not have write permission

    Parameters

    • pathName: string

      the directory path

    Returns Promise<number>

    Returns 0 for success

  • If file reading in chunks is supported on the current platform.

    Parameters

    • Optionalpath: string

    Returns boolean

  • Creates a symlink.

    Can throw:

    • FS_ERRORS.FSE-ENOENT when the parent dir does not exist or the given mode is not a file type
    • FS_ERRORS.FSE-EXISTS when the current path already exists
    • FS_ERRORS.FSE-EACCES-W if the parent directory does not have write permission

    Parameters

    • src: string

      The src path

    • dest: string

      The dest path

    Returns Promise<void>

    • Returns 0 for success
  • Deletes a file or a symlink.

    Can throw:

    • FS_ERRORS.FSE-ENOENT if the file does not exist
    • FS_ERRORS.FSE-EACCES-W if the file does not have write permission

    Parameters

    • pathName: string

    Returns Promise<number>

    • Returns 0 for success