import { VSBuffer, VSBufferReadable, VSBufferReadableStream } from '../../../base/common/buffer'; import { CancellationToken } from '../../../base/common/cancellation'; import { Event } from '../../../base/common/event'; import { IExpression } from '../../../base/common/glob'; import { IDisposable } from '../../../base/common/lifecycle'; import { TernarySearchTree } from '../../../base/common/map'; import { ReadableStreamEvents } from '../../../base/common/stream'; import { URI } from '../../../base/common/uri'; import type { ProgressCbArgs } from '../../../base/common/resources'; export interface IFileService { readonly _serviceBrand: undefined; /** * An event that is fired when a file system provider is added or removed */ readonly onDidChangeFileSystemProviderRegistrations: Event; /** * An event that is fired when a registered file system provider changes it's capabilities. */ readonly onDidChangeFileSystemProviderCapabilities: Event; /** * An event that is fired when a file system provider is about to be activated. Listeners * can join this event with a long running promise to help in the activation process. */ readonly onWillActivateFileSystemProvider: Event; /** * Registers a file system provider for a certain scheme. */ registerProvider(scheme: string, provider: IFileSystemProvider): IDisposable; /** * Returns a file system provider for a certain scheme. */ getProvider(scheme: string): IFileSystemProvider | undefined; /** * Tries to activate a provider with the given scheme. */ activateProvider(scheme: string): Promise; /** * Checks if this file service can handle the given resource by * first activating any extension that wants to be activated * on the provided resource scheme to include extensions that * contribute file system providers for the given resource. */ canHandleResource(resource: URI): Promise; /** * Checks if the file service has a registered provider for the * provided resource. * * Note: this does NOT account for contributed providers from * extensions that have not been activated yet. To include those, * consider to call `await fileService.canHandleResource(resource)`. */ hasProvider(resource: URI): boolean; /** * Checks if the provider for the provided resource has the provided file system capability. */ hasCapability(resource: URI, capability: FileSystemProviderCapabilities): boolean; /** * List the schemes and capabilies for registered file system providers */ listCapabilities(): Iterable<{ scheme: string; capabilities: FileSystemProviderCapabilities; }>; /** * Allows to listen for file changes. The event will fire for every file within the opened workspace * (if any) as well as all files that have been watched explicitly using the #watch() API. */ readonly onDidFilesChange: Event; /** * * Raw access to all file events emitted from file system providers. * * @deprecated use this method only if you know what you are doing. use the other watch related events * and APIs for more efficient file watching. */ readonly onDidChangeFilesRaw: Event; /** * An event that is fired upon successful completion of a certain file operation. */ readonly onDidRunOperation: Event; /** * Resolve the properties of a file/folder identified by the resource. * * If the optional parameter "resolveTo" is specified in options, the stat service is asked * to provide a stat object that should contain the full graph of folders up to all of the * target resources. * * If the optional parameter "resolveSingleChildDescendants" is specified in options, * the stat service is asked to automatically resolve child folders that only * contain a single element. * * If the optional parameter "resolveMetadata" is specified in options, * the stat will contain metadata information such as size, mtime and etag. */ resolve(resource: URI, options: IResolveMetadataFileOptions): Promise; resolve(resource: URI, options?: IResolveFileOptions): Promise; /** * Same as resolve() but supports resolving multiple resources in parallel. * If one of the resolve targets fails to resolve returns a fake IFileStat instead of making the whole call fail. */ resolveAll(toResolve: { resource: URI; options: IResolveMetadataFileOptions; }[]): Promise; resolveAll(toResolve: { resource: URI; options?: IResolveFileOptions; }[]): Promise; /** * Finds out if a file/folder identified by the resource exists. */ exists(resource: URI): Promise; /** * Read the contents of the provided resource unbuffered. */ readFile(resource: URI, options?: IReadFileOptions): Promise; /** * Read the contents of the provided resource buffered as stream. */ readFileStream(resource: URI, options?: IReadFileStreamOptions): Promise; /** * Updates the content replacing its previous value. */ writeFile(resource: URI, bufferOrReadableOrStream: VSBuffer | VSBufferReadable | VSBufferReadableStream, options?: IWriteFileOptions): Promise; /** * Moves the file/folder to a new path identified by the resource. * * The optional parameter overwrite can be set to replace an existing file at the location. */ move(source: URI, target: URI, overwrite?: boolean): Promise; move(source: URI, target: URI, overwrite?: boolean, additionalArgs?: { token?: CancellationToken; progressCb?: (args: ProgressCbArgs) => void; }): Promise; /** * Find out if a move operation is possible given the arguments. No changes on disk will * be performed. Returns an Error if the operation cannot be done. */ canMove(source: URI, target: URI, overwrite?: boolean): Promise; /** * Copies the file/folder to a path identified by the resource. * * The optional parameter overwrite can be set to replace an existing file at the location. */ copy(source: URI, target: URI, overwrite?: boolean): Promise; copy(source: URI, target: URI, overwrite?: boolean, additionalArgs?: { token?: CancellationToken; progressCb?: (args: ProgressCbArgs) => void; }): Promise; /** * Find out if a copy operation is possible given the arguments. No changes on disk will * be performed. Returns an Error if the operation cannot be done. */ canCopy(source: URI, target: URI, overwrite?: boolean): Promise; /** * Find out if a file create operation is possible given the arguments. No changes on disk will * be performed. Returns an Error if the operation cannot be done. */ canCreateFile(resource: URI, options?: ICreateFileOptions): Promise; /** * Creates a new file with the given path and optional contents. The returned promise * will have the stat model object as a result. * * The optional parameter content can be used as value to fill into the new file. */ createFile(resource: URI, bufferOrReadableOrStream?: VSBuffer | VSBufferReadable | VSBufferReadableStream, options?: ICreateFileOptions): Promise; /** * Creates a new folder with the given path. The returned promise * will have the stat model object as a result. */ createFolder(resource: URI): Promise; /** * Deletes the provided file. The optional useTrash parameter allows to * move the file to trash. The optional recursive parameter allows to delete * non-empty folders recursively. */ del(resource: URI, options?: Partial): Promise; /** * Find out if a delete operation is possible given the arguments. No changes on disk will * be performed. Returns an Error if the operation cannot be done. */ canDelete(resource: URI, options?: Partial): Promise; /** * Allows to start a watcher that reports file/folder change events on the provided resource. * * Note: watching a folder does not report events recursively for child folders yet. */ watch(resource: URI): IDisposable; /** * Frees up any resources occupied by this service. */ dispose(): void; } export interface FileOverwriteOptions { /** * Set to `true` to overwrite a file if it exists. Will * throw an error otherwise if the file does exist. */ readonly overwrite: boolean; } export interface FileUnlockOptions { /** * Set to `true` to try to remove any write locks the file might * have. A file that is write locked will throw an error for any * attempt to write to unless `unlock: true` is provided. */ readonly unlock: boolean; } export interface FileReadStreamOptions { /** * Is an integer specifying where to begin reading from in the file. If position is undefined, * data will be read from the current file position. */ readonly position?: number; /** * Is an integer specifying how many bytes to read from the file. By default, all bytes * will be read. */ readonly length?: number; /** * If provided, the size of the file will be checked against the limits. */ limits?: { readonly size?: number; readonly memory?: number; }; } export interface FileWriteOptions extends FileOverwriteOptions, FileUnlockOptions { /** * Set to `true` to create a file when it does not exist. Will * throw an error otherwise if the file does not exist. */ readonly create: boolean; } export declare type FileOpenOptions = FileOpenForReadOptions | FileOpenForWriteOptions; export declare function isFileOpenForWriteOptions(options: FileOpenOptions): options is FileOpenForWriteOptions; export interface FileOpenForReadOptions { /** * A hint that the file should be opened for reading only. */ readonly create: false; } export interface FileOpenForWriteOptions extends FileUnlockOptions { /** * A hint that the file should be opened for reading and writing. */ readonly create: true; } export interface FileDeleteOptions { /** * Set to `true` to recursively delete any children of the file. This * only applies to folders and can lead to an error unless provided * if the folder is not empty. */ readonly recursive: boolean; /** * Set to `true` to attempt to move the file to trash * instead of deleting it permanently from disk. This * option maybe not be supported on all providers. */ readonly useTrash: boolean; } export declare enum FileType { /** * File is unknown (neither file, directory nor symbolic link). */ Unknown = 0, /** * File is a normal file. */ File = 1, /** * File is a directory. */ Directory = 2, /** * File is a symbolic link. * * Note: even when the file is a symbolic link, you can test for * `FileType.File` and `FileType.Directory` to know the type of * the target the link points to. */ SymbolicLink = 64 } export declare enum FilePermission { /** * File is readonly. */ Readonly = 1 } export interface IStat { /** * The file type. */ readonly type: FileType; /** * The last modification date represented as millis from unix epoch. */ readonly mtime: number; /** * The creation date represented as millis from unix epoch. */ readonly ctime: number; /** * The size of the file in bytes. */ readonly size: number; /** * The file permissions. */ readonly permissions?: FilePermission; } export interface IWatchOptions { /** * Set to `true` to watch for changes recursively in a folder * and all of its children. */ readonly recursive: boolean; /** * A set of paths to exclude from watching. */ excludes: string[]; } export declare const enum FileSystemProviderCapabilities { /** * Provider supports unbuffered read/write. */ FileReadWrite = 2, /** * Provider supports open/read/write/close low level file operations. */ FileOpenReadWriteClose = 4, /** * Provider supports stream based reading. */ FileReadStream = 16, /** * Provider supports copy operation. */ FileFolderCopy = 8, /** * Provider is path case sensitive. */ PathCaseSensitive = 1024, /** * All files of the provider are readonly. */ Readonly = 2048, /** * Provider supports to delete via trash. */ Trash = 4096, /** * Provider support to unlock files for writing. */ FileWriteUnlock = 8192 } export interface IFileSystemProvider { readonly capabilities: FileSystemProviderCapabilities; readonly onDidChangeCapabilities: Event; readonly onDidErrorOccur?: Event; readonly onDidChangeFile: Event; watch(resource: URI, opts: IWatchOptions): IDisposable; stat(resource: URI): Promise; mkdir(resource: URI): Promise; readdir(resource: URI): Promise<[string, FileType][]>; delete(resource: URI, opts: FileDeleteOptions): Promise; rename(from: URI, to: URI, opts: FileOverwriteOptions): Promise; copy?(from: URI, to: URI, opts: FileOverwriteOptions): Promise; copy?(from: URI, to: URI, opts: FileOverwriteOptions, additionalArgs?: { token?: CancellationToken; progressCb?: (args: ProgressCbArgs) => void; }): Promise; readFile?(resource: URI): Promise; writeFile?(resource: URI, content: Uint8Array, opts: FileWriteOptions): Promise; readFileStream?(resource: URI, opts: FileReadStreamOptions, token: CancellationToken): ReadableStreamEvents; open?(resource: URI, opts: FileOpenOptions): Promise; close?(fd: number): Promise; read?(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise; write?(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise; } export interface IFileSystemProviderWithFileReadWriteCapability extends IFileSystemProvider { readFile(resource: URI): Promise; writeFile(resource: URI, content: Uint8Array, opts: FileWriteOptions): Promise; } export declare function hasReadWriteCapability(provider: IFileSystemProvider): provider is IFileSystemProviderWithFileReadWriteCapability; export interface IFileSystemProviderWithFileFolderCopyCapability extends IFileSystemProvider { copy(from: URI, to: URI, opts: FileOverwriteOptions, additionalArgs?: { token?: CancellationToken; progressCb?: (args: ProgressCbArgs) => void; }): Promise; } export declare function hasFileFolderCopyCapability(provider: IFileSystemProvider): provider is IFileSystemProviderWithFileFolderCopyCapability; export interface IFileSystemProviderWithOpenReadWriteCloseCapability extends IFileSystemProvider { open(resource: URI, opts: FileOpenOptions): Promise; close(fd: number): Promise; read(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise; write(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise; } export declare function hasOpenReadWriteCloseCapability(provider: IFileSystemProvider): provider is IFileSystemProviderWithOpenReadWriteCloseCapability; export interface IFileSystemProviderWithFileReadStreamCapability extends IFileSystemProvider { readFileStream(resource: URI, opts: FileReadStreamOptions, token: CancellationToken): ReadableStreamEvents; } export declare function hasFileReadStreamCapability(provider: IFileSystemProvider): provider is IFileSystemProviderWithFileReadStreamCapability; export declare enum FileSystemProviderErrorCode { FileExists = "EntryExists", FileNotFound = "EntryNotFound", FileNotADirectory = "EntryNotADirectory", FileIsADirectory = "EntryIsADirectory", FileExceedsMemoryLimit = "EntryExceedsMemoryLimit", FileTooLarge = "EntryTooLarge", FileWriteLocked = "EntryWriteLocked", NoPermissions = "NoPermissions", Unavailable = "Unavailable", Unknown = "Unknown" } export declare class FileSystemProviderError extends Error { readonly code: FileSystemProviderErrorCode; constructor(message: string, code: FileSystemProviderErrorCode); } export declare function createFileSystemProviderError(error: Error | string, code: FileSystemProviderErrorCode): FileSystemProviderError; export declare function ensureFileSystemProviderError(error?: Error): Error; export declare function markAsFileSystemProviderError(error: Error, code: FileSystemProviderErrorCode): Error; export declare function toFileSystemProviderErrorCode(error: Error | undefined | null): FileSystemProviderErrorCode; export declare function toFileOperationResult(error: Error): FileOperationResult; export interface IFileSystemProviderRegistrationEvent { readonly added: boolean; readonly scheme: string; readonly provider?: IFileSystemProvider; } export interface IFileSystemProviderCapabilitiesChangeEvent { readonly provider: IFileSystemProvider; readonly scheme: string; } export interface IFileSystemProviderActivationEvent { readonly scheme: string; join(promise: Promise): void; } export declare const enum FileOperation { CREATE = 0, DELETE = 1, MOVE = 2, COPY = 3 } export declare class FileOperationEvent { readonly resource: URI; readonly operation: FileOperation; readonly target?: IFileStatWithMetadata | undefined; constructor(resource: URI, operation: FileOperation.DELETE); constructor(resource: URI, operation: FileOperation.CREATE | FileOperation.MOVE | FileOperation.COPY, target: IFileStatWithMetadata); isOperation(operation: FileOperation.DELETE): boolean; isOperation(operation: FileOperation.MOVE | FileOperation.COPY | FileOperation.CREATE): this is { readonly target: IFileStatWithMetadata; }; } /** * Possible changes that can occur to a file. */ export declare const enum FileChangeType { UPDATED = 0, ADDED = 1, DELETED = 2 } /** * Identifies a single change in a file. */ export interface IFileChange { /** * The type of change that occurred to the file. */ readonly type: FileChangeType; /** * The unified resource identifier of the file that changed. */ readonly resource: URI; } export interface IRawFileChangesEvent { /** * @deprecated use `FileChangesEvent` instead unless you know what you are doing */ readonly changes: readonly IFileChange[]; } export declare class FileChangesEvent { private readonly added; private readonly updated; private readonly deleted; constructor(changes: readonly IFileChange[], ignorePathCasing: boolean); /** * Find out if the file change events match the provided resource. * * Note: when passing `FileChangeType.DELETED`, we consider a match * also when the parent of the resource got deleted. */ contains(resource: URI, ...types: FileChangeType[]): boolean; /** * Find out if the file change events either match the provided * resource, or contain a child of this resource. */ affects(resource: URI, ...types: FileChangeType[]): boolean; private doContains; /** * Returns if this event contains added files. */ gotAdded(): boolean; /** * Returns if this event contains deleted files. */ gotDeleted(): boolean; /** * Returns if this event contains updated files. */ gotUpdated(): boolean; /** * @deprecated use the `contains` or `affects` method to efficiently find * out if the event relates to a given resource. these methods ensure: * - that there is no expensive lookup needed (by using a `TernarySearchTree`) * - correctly handles `FileChangeType.DELETED` events */ get rawAdded(): TernarySearchTree | undefined; /** * @deprecated use the `contains` or `affects` method to efficiently find * out if the event relates to a given resource. these methods ensure: * - that there is no expensive lookup needed (by using a `TernarySearchTree`) * - correctly handles `FileChangeType.DELETED` events */ get rawDeleted(): TernarySearchTree | undefined; } export declare function isParent(path: string, candidate: string, ignoreCase?: boolean): boolean; interface IBaseStat { /** * The unified resource identifier of this file or folder. */ readonly resource: URI; /** * The name which is the last segment * of the {{path}}. */ readonly name: string; /** * The size of the file. * * The value may or may not be resolved as * it is optional. */ readonly size?: number; /** * The last modification date represented as millis from unix epoch. * * The value may or may not be resolved as * it is optional. */ readonly mtime?: number; /** * The creation date represented as millis from unix epoch. * * The value may or may not be resolved as * it is optional. */ readonly ctime?: number; /** * A unique identifier thet represents the * current state of the file or directory. * * The value may or may not be resolved as * it is optional. */ readonly etag?: string; /** * The file is read-only. */ readonly readonly?: boolean; } export interface IBaseStatWithMetadata extends Required { } /** * A file resource with meta information. */ export interface IFileStat extends IBaseStat { /** * The resource is a file. */ readonly isFile: boolean; /** * The resource is a directory. */ readonly isDirectory: boolean; /** * The resource is a symbolic link. Note: even when the * file is a symbolic link, you can test for `FileType.File` * and `FileType.Directory` to know the type of the target * the link points to. */ readonly isSymbolicLink: boolean; /** * The children of the file stat or undefined if none. */ children?: IFileStat[]; } export interface IFileStatWithMetadata extends IFileStat, IBaseStatWithMetadata { readonly mtime: number; readonly ctime: number; readonly etag: string; readonly size: number; readonly readonly: boolean; readonly children?: IFileStatWithMetadata[]; } export interface IResolveFileResult { readonly stat?: IFileStat; readonly success: boolean; } export interface IResolveFileResultWithMetadata extends IResolveFileResult { readonly stat?: IFileStatWithMetadata; } export interface IFileContent extends IBaseStatWithMetadata { /** * The content of a file as buffer. */ readonly value: VSBuffer; } export interface IFileStreamContent extends IBaseStatWithMetadata { /** * The content of a file as stream. */ readonly value: VSBufferReadableStream; } export interface IBaseReadFileOptions extends FileReadStreamOptions { /** * The optional etag parameter allows to return early from resolving the resource if * the contents on disk match the etag. This prevents accumulated reading of resources * that have been read already with the same etag. * It is the task of the caller to makes sure to handle this error case from the promise. */ readonly etag?: string; } export interface IReadFileStreamOptions extends IBaseReadFileOptions { } export interface IReadFileOptions extends IBaseReadFileOptions { /** * The optional `atomic` flag can be used to make sure * the `readFile` method is not running in parallel with * any `write` operations in the same process. * * Typically you should not need to use this flag but if * for example you are quickly reading a file right after * a file event occurred and the file changes a lot, there * is a chance that a read returns an empty or partial file * because a pending write has not finished yet. * * Note: this does not prevent the file from being written * to from a different process. If you need such atomic * operations, you better use a real database as storage. */ readonly atomic?: boolean; } export interface IWriteFileOptions { /** * The last known modification time of the file. This can be used to prevent dirty writes. */ readonly mtime?: number; /** * The etag of the file. This can be used to prevent dirty writes. */ readonly etag?: string; /** * Whether to attempt to unlock a file before writing. */ readonly unlock?: boolean; } export interface IResolveFileOptions { /** * Automatically continue resolving children of a directory until the provided resources * are found. */ readonly resolveTo?: readonly URI[]; /** * Automatically continue resolving children of a directory if the number of children is 1. */ readonly resolveSingleChildDescendants?: boolean; /** * Will resolve mtime, ctime, size and etag of files if enabled. This can have a negative impact * on performance and thus should only be used when these values are required. */ readonly resolveMetadata?: boolean; } export interface IResolveMetadataFileOptions extends IResolveFileOptions { readonly resolveMetadata: true; } export interface ICreateFileOptions { /** * Overwrite the file to create if it already exists on disk. Otherwise * an error will be thrown (FILE_MODIFIED_SINCE). */ readonly overwrite?: boolean; } export declare class FileOperationError extends Error { readonly fileOperationResult: FileOperationResult; readonly options?: (IReadFileOptions & IWriteFileOptions & ICreateFileOptions) | undefined; constructor(message: string, fileOperationResult: FileOperationResult, options?: (IReadFileOptions & IWriteFileOptions & ICreateFileOptions) | undefined); } export declare class NotModifiedSinceFileOperationError extends FileOperationError { readonly stat: IFileStatWithMetadata; constructor(message: string, stat: IFileStatWithMetadata, options?: IReadFileOptions); } export declare const enum FileOperationResult { FILE_IS_DIRECTORY = 0, FILE_NOT_FOUND = 1, FILE_NOT_MODIFIED_SINCE = 2, FILE_MODIFIED_SINCE = 3, FILE_MOVE_CONFLICT = 4, FILE_WRITE_LOCKED = 5, FILE_PERMISSION_DENIED = 6, FILE_TOO_LARGE = 7, FILE_INVALID_PATH = 8, FILE_EXCEEDS_MEMORY_LIMIT = 9, FILE_NOT_DIRECTORY = 10, FILE_OTHER_ERROR = 11 } export declare const AutoSaveConfiguration: { OFF: string; AFTER_DELAY: string; ON_FOCUS_CHANGE: string; ON_WINDOW_CHANGE: string; }; export declare const HotExitConfiguration: { OFF: string; ON_EXIT: string; ON_EXIT_AND_WINDOW_CLOSE: string; }; export declare const FILES_ASSOCIATIONS_CONFIG = "files.associations"; export declare const FILES_EXCLUDE_CONFIG = "files.exclude"; export interface IFilesConfiguration { files: { associations: { [filepattern: string]: string; }; exclude: IExpression; watcherExclude: { [filepattern: string]: boolean; }; watcherInclude: string[]; encoding: string; autoGuessEncoding: boolean; defaultLanguage: string; trimTrailingWhitespace: boolean; autoSave: string; autoSaveDelay: number; eol: string; enableTrash: boolean; hotExit: string; saveConflictResolution: 'askUser' | 'overwriteFileOnDisk'; }; } export declare enum FileKind { FILE = 0, FOLDER = 1, ROOT_FOLDER = 2 } /** * A hint to disable etag checking for reading/writing. */ export declare const ETAG_DISABLED = ""; export declare function etag(stat: { mtime: number; size: number; }): string; export declare function etag(stat: { mtime: number | undefined; size: number | undefined; }): string | undefined; export declare function whenProviderRegistered(file: URI, fileService: IFileService): Promise; /** * Native only: limits for memory sizes */ export declare const MIN_MAX_MEMORY_SIZE_MB = 2048; export declare const FALLBACK_MAX_MEMORY_SIZE_MB = 4096; /** * Helper to format a raw byte size into a human readable label. */ export declare class ByteSize { static readonly KB = 1024; static readonly MB: number; static readonly GB: number; static readonly TB: number; static formatSize(size: number): string; } export interface IArchLimits { readonly maxFileSize: number; readonly maxHeapSize: number; } export declare const enum Arch { IA32 = 0, OTHER = 1 } export declare function getPlatformLimits(arch: Arch): IArchLimits; export {}; //# sourceMappingURL=files.d.ts.map