UNPKG

@fairdatasociety/fairdrive-opfs

Version:

Fairdrive OPFS - integrate data sources from Web 2.0 or Web 3.0

118 lines (117 loc) 3.52 kB
/// <reference types="wicg-file-system-access" /> import { FileSystemFileHandleAdapter, FileSystemFolderHandleAdapter, WriteChunk } from 'file-system-access/lib/interfaces'; import { Subject } from 'rxjs'; import { FileSync } from './file-sync'; import { ProviderDriver } from './provider-driver'; export interface Entries { files: Array<string>; dirs: Array<string>; mount: Mount; } /** * FdpConnectProvider is the base class for all providers. */ export declare abstract class FdpConnectProvider { private config; onMount: Subject<Mount>; mount: Mount; constructor(config: any); filesystemDriver: ProviderDriver; initialize(options: any): void; /** * Get the current mount point. * @returns Current mount point */ getCurrentMount(): Mount; /** * getFSHandler returns a FileSystemDirectoryHandle for the given provider. * @param mount - mount point * @returns a FileSystemDirectoryHandle */ getFSHandler(mount: Mount): Promise<FileSystemDirectoryHandle>; /** * getTransferHandler returns a FileSync for the given provider. * @returns a FileSync */ getTransferHandler(): FileSync; } /** * Mount represents a logical mount point for a provider to be mounted on. */ export interface Mount { path: string; name: string; } declare class Sink implements UnderlyingSink<WriteChunk> { private file; driver: ProviderDriver; mount: Mount; constructor(mount: Mount, driver: ProviderDriver, file: File); /** * Returns true if the file exists, else false * @param key * @param options * @returns */ has(key: string): Promise<boolean>; /** * Write a chunk to the file */ write(chunk: WriteChunk): Promise<void>; /** * Close the file */ close(): Promise<void>; } export declare class FileHandle implements FileSystemFileHandleAdapter { readonly name: string; readonly kind = "file"; mount: Mount; driver: ProviderDriver; onclose?(self: this): void; writable: boolean; constructor(mount: Mount, driver: ProviderDriver, name: string); /** * Get the file */ getFile(): Promise<File>; /** * Create a writable stream */ createWritable(opts?: FileSystemCreateWritableOptions): Promise<Sink>; /** * Check if the file is the same as the other file */ isSameEntry(other: FileHandle): Promise<boolean>; } export declare class FolderHandle implements FileSystemFolderHandleAdapter { readonly path: string; readonly kind = "directory"; readonly name: string; mount: Mount; writable: boolean; readable: boolean; driver: ProviderDriver; constructor(mount: Mount, driver: ProviderDriver); /** * Entries returns a list of files and directories */ entries(): AsyncGenerator<[string, FolderHandle] | [string, FileHandle], void, unknown>; /** * Check if the folder is the same as the other folder */ isSameEntry(other: FolderHandle): Promise<boolean>; /** * GetDirectoryHandle returns a directory handle */ getDirectoryHandle(name: string, opts?: FileSystemGetDirectoryOptions): Promise<FolderHandle>; /** * GetFileHandle returns a file handle */ getFileHandle(name: string, opts?: FileSystemGetFileOptions): Promise<FileHandle>; /** * Removes a file */ removeEntry(name: string, opts?: FileSystemRemoveOptions): Promise<void>; } export {};