1
>
/*---------------------------------------------------------------------------------------------
files.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { VSBuffer, VSBufferReadable, VSBufferReadableStream } from '../../../base/common/buffer.js';
7
>
import { CancellationToken } from '../../../base/common/cancellation.js';
8
>
import { Event } from '../../../base/common/event.js';
9
>
import { IExpression, IRelativePattern } from '../../../base/common/glob.js';
10
>
import { IDisposable } from '../../../base/common/lifecycle.js';
11
>
import { TernarySearchTree } from '../../../base/common/ternarySearchTree.js';
12
>
import { sep } from '../../../base/common/path.js';
13
>
import { ReadableStreamEvents } from '../../../base/common/stream.js';
14
>
import { startsWithIgnoreCase } from '../../../base/common/strings.js';
15
>
import { isNumber } from '../../../base/common/types.js';
16
>
import { URI } from '../../../base/common/uri.js';
17
>
import { localize } from '../../../nls.js';
18
>
import { createDecorator } from '../../instantiation/common/instantiation.js';
19
>
import { isWeb } from '../../../base/common/platform.js';
20
>
import { Schemas } from '../../../base/common/network.js';
21
>
import { IMarkdownString } from '../../../base/common/htmlContent.js';
22
>
import { Lazy } from '../../../base/common/lazy.js';
23
>
24
>
//#region file service & providers
25
>
26
>
export const IFileService = createDecorator<IFileService>('fileService');
27
>
28
>
export interface IFileService {
29
>
30
>
readonly _serviceBrand: undefined;
31
>
32
>
/**
33
>
* An event that is fired when a file system provider is added or removed
34
>
*/
35
>
readonly onDidChangeFileSystemProviderRegistrations: Event<IFileSystemProviderRegistrationEvent>;
36
>
37
>
/**
38
>
* An event that is fired when a registered file system provider changes its capabilities.
39
>
*/
40
>
readonly onDidChangeFileSystemProviderCapabilities: Event<IFileSystemProviderCapabilitiesChangeEvent>;
41
>
42
>
/**
43
>
* An event that is fired when a file system provider is about to be activated. Listeners
44
>
* can join this event with a long running promise to help in the activation process.
45
>
*/
46
>
readonly onWillActivateFileSystemProvider: Event<IFileSystemProviderActivationEvent>;
47
>
48
>
/**
49
>
* Registers a file system provider for a certain scheme.
50
>
*/
51
>
registerProvider(scheme: string, provider: IFileSystemProvider): IDisposable;
52
>
53
>
/**
54
>
* Returns a file system provider for a certain scheme.
55
>
*/
56
>
getProvider(scheme: string): IFileSystemProvider | undefined;
57
>
58
>
/**
59
>
* Tries to activate a provider with the given scheme.
60
>
*/
61
>
activateProvider(scheme: string): Promise<void>;
62
>
63
>
/**
64
>
* Checks if this file service can handle the given resource by
65
>
* first activating any extension that wants to be activated
66
>
* on the provided resource scheme to include extensions that
67
>
* contribute file system providers for the given resource.
68
>
*/
69
>
canHandleResource(resource: URI): Promise<boolean>;
70
>
71
>
/**
72
>
* Checks if the file service has a registered provider for the
73
>
* provided resource.
74
>
*
75
>
* Note: this does NOT account for contributed providers from
76
>
* extensions that have not been activated yet. To include those,
77
>
* consider to call `await fileService.canHandleResource(resource)`.
78
>
*/
79
>
hasProvider(resource: URI): boolean;
80
>
81
>
/**
82
>
* Checks if the provider for the provided resource has the provided file system capability.
83
>
*/
84
>
hasCapability(resource: URI, capability: FileSystemProviderCapabilities): boolean;
85
>
86
>
/**
87
>
* List the schemes and capabilities for registered file system providers
88
>
*/
89
>
listCapabilities(): Iterable<{ scheme: string; capabilities: FileSystemProviderCapabilities }>;
90
>
91
>
/**
92
>
* Allows to listen for file changes. The event will fire for every file within the opened workspace
93
>
* (if any) as well as all files that have been watched explicitly using the #watch() API.
94
>
*/
95
>
readonly onDidFilesChange: Event<FileChangesEvent>;
96
>
97
>
/**
98
>
* An event that is fired upon successful completion of a certain file operation.
99
>
*/
100
>
readonly onDidRunOperation: Event<FileOperationEvent>;
101
>
102
>
/**
103
>
* Resolve the properties of a file/folder identified by the resource. For a folder, children
104
>
* information is resolved as well depending on the provided options. Use `stat()` method if
105
>
* you do not need children information.
106
>
*
107
>
* If the optional parameter "resolveTo" is specified in options, the stat service is asked
108
>
* to provide a stat object that should contain the full graph of folders up to all of the
109
>
* target resources.
110
>
*
111
>
* If the optional parameter "resolveSingleChildDescendants" is specified in options,
112
>
* the stat service is asked to automatically resolve child folders that only
113
>
* contain a single element.
114
>
*
115
>
* If the optional parameter "resolveMetadata" is specified in options,
116
>
* the stat will contain metadata information such as size, mtime and etag.
117
>
*/
118
>
resolve(resource: URI, options: IResolveMetadataFileOptions): Promise<IFileStatWithMetadata>;
119
>
resolve(resource: URI, options?: IResolveFileOptions): Promise<IFileStat>;
120
>
121
>
/**
122
>
* Same as `resolve()` but supports resolving multiple resources in parallel.
123
>
*
124
>
* If one of the resolve targets fails to resolve returns a fake `IFileStat` instead of
125
>
* making the whole call fail.
126
>
*/
127
>
resolveAll(toResolve: { resource: URI; options: IResolveMetadataFileOptions }[]): Promise<IFileStatResult[]>;
128
>
resolveAll(toResolve: { resource: URI; options?: IResolveFileOptions }[]): Promise<IFileStatResult[]>;
129
>
130
>
/**
131
>
* Same as `resolve()` but without resolving the children of a folder if the
132
>
* resource is pointing to a folder.
133
>
*/
134
>
stat(resource: URI): Promise<IFileStatWithPartialMetadata>;
135
>
136
>
/**
137
>
* Attempts to resolve the real path of the provided resource. The real path can be
138
>
* different from the resource path for example when it is a symlink.
139
>
*
140
>
* Will return `undefined` if the real path cannot be resolved.
141
>
*/
142
>
realpath(resource: URI): Promise<URI | undefined>;
143
>
144
>
/**
145
>
* Finds out if a file/folder identified by the resource exists.
146
>
*/
147
>
exists(resource: URI): Promise<boolean>;
148
>
149
>
/**
150
>
* Read the contents of the provided resource unbuffered.
151
>
*/
152
>
readFile(resource: URI, options?: IReadFileOptions, token?: CancellationToken): Promise<IFileContent>;
153
>
154
>
/**
155
>
* Read the contents of the provided resource buffered as stream.
156
>
*/
157
>
readFileStream(resource: URI, options?: IReadFileStreamOptions, token?: CancellationToken): Promise<IFileStreamContent>;
158
>
159
>
/**
160
>
* Updates the content replacing its previous value.
161
>
* If `options.append` is true, appends content to the end of the file instead.
162
>
*
163
>
* Emits a `FileOperation.WRITE` file operation event when successful.
164
>
*/
165
>
writeFile(resource: URI, bufferOrReadableOrStream: VSBuffer | VSBufferReadable | VSBufferReadableStream, options?: IWriteFileOptions): Promise<IFileStatWithMetadata>;
166
>
167
>
/**
168
>
* Moves the file/folder to a new path identified by the resource.
169
>
*
170
>
* The optional parameter overwrite can be set to replace an existing file at the location.
171
>
*
172
>
* Emits a `FileOperation.MOVE` file operation event when successful.
173
>
*/
174
>
move(source: URI, target: URI, overwrite?: boolean): Promise<IFileStatWithMetadata>;
175
>
176
>
/**
177
>
* Find out if a move operation is possible given the arguments. No changes on disk will
178
>
* be performed. Returns an Error if the operation cannot be done.
179
>
*/
180
>
canMove(source: URI, target: URI, overwrite?: boolean): Promise<Error | true>;
181
>
182
>
/**
183
>
* Copies the file/folder to a path identified by the resource. A folder is copied
184
>
* recursively.
185
>
*
186
>
* Emits a `FileOperation.COPY` file operation event when successful.
187
>
*/
188
>
copy(source: URI, target: URI, overwrite?: boolean): Promise<IFileStatWithMetadata>;
189
>
190
>
/**
191
>
* Find out if a copy operation is possible given the arguments. No changes on disk will
192
>
* be performed. Returns an Error if the operation cannot be done.
193
>
*/
194
>
canCopy(source: URI, target: URI, overwrite?: boolean): Promise<Error | true>;
195
>
196
>
/**
197
>
* Clones a file to a path identified by the resource. Folders are not supported.
198
>
*
199
>
* If the target path exists, it will be overwritten.
200
>
*/
201
>
cloneFile(source: URI, target: URI): Promise<void>;
202
>
203
>
/**
204
>
* Creates a new file with the given path and optional contents. The returned promise
205
>
* will have the stat model object as a result.
206
>
*
207
>
* The optional parameter content can be used as value to fill into the new file.
208
>
*
209
>
* Emits a `FileOperation.CREATE` file operation event when successful.
210
>
*/
211
>
createFile(resource: URI, bufferOrReadableOrStream?: VSBuffer | VSBufferReadable | VSBufferReadableStream, options?: ICreateFileOptions): Promise<IFileStatWithMetadata>;
212
>
213
>
/**
214
>
* Find out if a file create operation is possible given the arguments. No changes on disk will
215
>
* be performed. Returns an Error if the operation cannot be done.
216
>
*/
217
>
canCreateFile(resource: URI, options?: ICreateFileOptions): Promise<Error | true>;
218
>
219
>
/**
220
>
* Creates a new folder with the given path. The returned promise
221
>
* will have the stat model object as a result.
222
>
*
223
>
* Emits a `FileOperation.CREATE` file operation event when successful.
224
>
*/
225
>
createFolder(resource: URI): Promise<IFileStatWithMetadata>;
226
>
227
>
/**
228
>
* Deletes the provided file. The optional useTrash parameter allows to
229
>
* move the file to trash. The optional recursive parameter allows to delete
230
>
* non-empty folders recursively.
231
>
*
232
>
* Emits a `FileOperation.DELETE` file operation event when successful.
233
>
*/
234
>
del(resource: URI, options?: Partial<IFileDeleteOptions>): Promise<void>;
235
>
236
>
/**
237
>
* Find out if a delete operation is possible given the arguments. No changes on disk will
238
>
* be performed. Returns an Error if the operation cannot be done.
239
>
*/
240
>
canDelete(resource: URI, options?: Partial<IFileDeleteOptions>): Promise<Error | true>;
241
>
242
>
/**
243
>
* An event that signals an error when watching for file changes.
244
>
*/
245
>
readonly onDidWatchError: Event<Error>;
246
>
247
>
/**
248
>
* Allows to start a watcher that reports file/folder change events on the provided resource.
249
>
*
250
>
* The watcher runs correlated and thus, file events will be reported on the returned
251
>
* `IFileSystemWatcher` and not on the generic `IFileService.onDidFilesChange` event.
252
>
*
253
>
* Note: only non-recursive file watching supports event correlation for now.
254
>
*/
255
>
createWatcher(resource: URI, options: IWatchOptionsWithoutCorrelation & { recursive: false }): IFileSystemWatcher;
256
>
257
>
/**
258
>
* Allows to start a watcher that reports file/folder change events on the provided resource.
259
>
*
260
>
* The watcher runs uncorrelated and thus will report all events from `IFileService.onDidFilesChange`.
261
>
* This means, most listeners in the application will receive your events. It is encouraged to
262
>
* use correlated watchers (via `IWatchOptionsWithCorrelation`) to limit events to your listener.
263
>
*/
264
>
watch(resource: URI, options?: IWatchOptionsWithoutCorrelation): IDisposable;
265
>
266
>
/**
267
>
* Frees up any resources occupied by this service.
268
>
*/
269
>
dispose(): void;
270
>
}
271
>
272
>
export interface IFileOverwriteOptions {
273
>
274
>
/**
275
>
* Set to `true` to overwrite a file if it exists. Will
276
>
* throw an error otherwise if the file does exist.
277
>
*/
278
>
readonly overwrite: boolean;
279
>
}
280
>
281
>
export interface IFileUnlockOptions {
282
>
283
>
/**
284
>
* Set to `true` to try to remove any write locks the file might
285
>
* have. A file that is write locked will throw an error for any
286
>
* attempt to write to unless `unlock: true` is provided.
287
>
*/
288
>
readonly unlock: boolean;
289
>
}
290
>
291
>
export interface IFileAtomicReadOptions {
292
>
293
>
/**
294
>
* The optional `atomic` flag can be used to make sure
295
>
* the `readFile` method is not running in parallel with
296
>
* any `write` operations in the same process.
297
>
*
298
>
* Typically you should not need to use this flag but if
299
>
* for example you are quickly reading a file right after
300
>
* a file event occurred and the file changes a lot, there
301
>
* is a chance that a read returns an empty or partial file
302
>
* because a pending write has not finished yet.
303
>
*
304
>
* Note: this does not prevent the file from being written
305
>
* to from a different process. If you need such atomic
306
>
* operations, you better use a real database as storage.
307
>
*/
308
>
readonly atomic: boolean;
309
>
}
310
>
311
>
export interface IFileAtomicOptions {
312
>
313
>
/**
314
>
* The postfix is used to create a temporary file based
315
>
* on the original resource. The resulting temporary
316
>
* file will be in the same folder as the resource and
317
>
* have `postfix` appended to the resource name.
318
>
*
319
>
* Example: given a file resource `file:///some/path/foo.txt`
320
>
* and a postfix `.vsctmp`, the temporary file will be
321
>
* created as `file:///some/path/foo.txt.vsctmp`.
322
>
*/
323
>
readonly postfix: string;
324
>
}
325
>
326
>
export interface IFileAtomicWriteOptions {
327
>
328
>
/**
329
>
* The optional `atomic` flag can be used to make sure
330
>
* the `writeFile` method updates the target file atomically
331
>
* by first writing to a temporary file in the same folder
332
>
* and then renaming it over the target.
333
>
*/
334
>
readonly atomic: IFileAtomicOptions | false;
335
>
}
336
>
337
>
export interface IFileAtomicDeleteOptions {
338
>
339
>
/**
340
>
* The optional `atomic` flag can be used to make sure
341
>
* the `delete` method deletes the target atomically by
342
>
* first renaming it to a temporary resource in the same
343
>
* folder and then deleting it.
344
>
*/
345
>
readonly atomic: IFileAtomicOptions | false;
346
>
}
347
>
348
>
export interface IFileReadLimits {
349
>
350
>
/**
351
>
* If the file exceeds the given size, an error of kind
352
>
* `FILE_TOO_LARGE` will be thrown.
353
>
*/
354
>
size?: number;
355
>
}
356
>
357
>
export interface IFileReadStreamOptions {
358
>
359
>
/**
360
>
* Is an integer specifying where to begin reading from in the file. If position is undefined,
361
>
* data will be read from the current file position.
362
>
*/
363
>
readonly position?: number;
364
>
365
>
/**
366
>
* Is an integer specifying how many bytes to read from the file. By default, all bytes
367
>
* will be read.
368
>
*/
369
>
readonly length?: number;
370
>
371
>
/**
372
>
* If provided, the size of the file will be checked against the limits
373
>
* and an error will be thrown if any limit is exceeded.
374
>
*/
375
>
readonly limits?: IFileReadLimits;
376
>
}
377
>
378
>
export interface IFileWriteOptions extends IFileOverwriteOptions, IFileUnlockOptions, IFileAtomicWriteOptions {
379
>
380
>
/**
381
>
* Set to `true` to create a file when it does not exist. Will
382
>
* throw an error otherwise if the file does not exist.
383
>
*/
384
>
readonly create: boolean;
385
>
386
>
/**
387
>
* Set to `true` to append content to the end of the file. Implies `create: true`,
388
>
* and set only when the corresponding `FileAppend` capability is defined.
389
>
*/
390
>
readonly append?: boolean;
391
>
}
392
>
393
>
export type IFileOpenOptions = IFileOpenForReadOptions | IFileOpenForWriteOptions;
394
>
395
>
export function isFileOpenForWriteOptions(options: IFileOpenOptions): options is IFileOpenForWriteOptions {
396
return options.create === true;
397
}
399
>
export interface IFileOpenForReadOptions {
400
>
401
>
/**
402
>
* A hint that the file should be opened for reading only.
403
>
*/
404
>
readonly create: false;
405
>
}
406
>
407
>
export interface IFileOpenForWriteOptions extends IFileUnlockOptions {
408
>
409
>
/**
410
>
* A hint that the file should be opened for reading and writing.
411
>
*/
412
>
readonly create: true;
413
>
414
>
/**
415
>
* Open the file in append mode. This will write data to the
416
>
* end of the file.
417
>
*/
418
>
readonly append?: boolean;
419
>
}
420
>
421
>
export interface IFileDeleteOptions {
422
>
423
>
/**
424
>
* Set to `true` to recursively delete any children of the file. This
425
>
* only applies to folders and can lead to an error unless provided
426
>
* if the folder is not empty.
427
>
*/
428
>
readonly recursive: boolean;
429
>
430
>
/**
431
>
* Set to `true` to attempt to move the file to trash
432
>
* instead of deleting it permanently from disk.
433
>
*
434
>
* This option maybe not be supported on all providers.
435
>
*/
436
>
readonly useTrash: boolean;
437
>
438
>
/**
439
>
* The optional `atomic` flag can be used to make sure
440
>
* the `delete` method deletes the target atomically by
441
>
* first renaming it to a temporary resource in the same
442
>
* folder and then deleting it.
443
>
*
444
>
* This option maybe not be supported on all providers.
445
>
*/
446
>
readonly atomic: IFileAtomicOptions | false;
447
>
}
448
>
449
>
export enum FileType {
450
>
451
>
/**
452
>
* File is unknown (neither file, directory nor symbolic link).
453
>
*/
454
>
Unknown = 0,
455
>
456
>
/**
457
>
* File is a normal file.
458
>
*/
459
>
File = 1,
460
>
461
>
/**
462
>
* File is a directory.
463
>
*/
464
>
Directory = 2,
465
>
466
>
/**
467
>
* File is a symbolic link.
468
>
*
469
>
* Note: even when the file is a symbolic link, you can test for
470
>
* `FileType.File` and `FileType.Directory` to know the type of
471
>
* the target the link points to.
472
>
*/
473
>
SymbolicLink = 64
474
>
}
475
>
476
>
export enum FilePermission {
477
>
478
>
/**
479
>
* File is readonly. Components like editors should not
480
>
* offer to edit the contents.
481
>
*/
482
>
Readonly = 1,
483
>
484
>
/**
485
>
* File is locked. Components like editors should offer
486
>
* to edit the contents and ask the user upon saving to
487
>
* remove the lock.
488
>
*/
489
>
Locked = 2,
490
>
491
>
/**
492
>
* File is executable. Relevant for Unix-like systems where
493
>
* the executable bit determines if a file can be run.
494
>
*/
495
>
Executable = 4
496
>
}
497
>
498
>
export interface IStat {
499
>
500
>
/**
501
>
* The file type.
502
>
*/
503
>
readonly type: FileType;
504
>
505
>
/**
506
>
* The last modification date represented as millis from unix epoch.
507
>
*/
508
>
readonly mtime: number;
509
>
510
>
/**
511
>
* The creation date represented as millis from unix epoch.
512
>
*/
513
>
readonly ctime: number;
514
>
515
>
/**
516
>
* The size of the file in bytes.
517
>
*/
518
>
readonly size: number;
519
>
520
>
/**
521
>
* The file permissions.
522
>
*/
523
>
readonly permissions?: FilePermission;
524
>
}
525
>
526
>
export interface IWatchOptionsWithoutCorrelation {
527
>
528
>
/**
529
>
* Set to `true` to watch for changes recursively in a folder
530
>
* and all of its children.
531
>
*/
532
>
recursive: boolean;
533
>
534
>
/**
535
>
* A set of glob patterns or paths to exclude from watching.
536
>
* Paths can be relative or absolute and when relative are
537
>
* resolved against the watched folder. Glob patterns are
538
>
* always matched relative to the watched folder.
539
>
*/
540
>
excludes: string[];
541
>
542
>
/**
543
>
* An optional set of glob patterns or paths to include for
544
>
* watching. If not provided, all paths are considered for
545
>
* events.
546
>
* Paths can be relative or absolute and when relative are
547
>
* resolved against the watched folder. Glob patterns are
548
>
* always matched relative to the watched folder.
549
>
*/
550
>
includes?: Array<string | IRelativePattern>;
551
>
552
>
/**
553
>
* If provided, allows to filter the events that the watcher should consider
554
>
* for emitting. If not provided, all events are emitted.
555
>
*
556
>
* For example, to emit added and updated events, set to:
557
>
* `FileChangeFilter.ADDED | FileChangeFilter.UPDATED`.
558
>
*/
559
>
filter?: FileChangeFilter;
560
>
}
561
>
562
>
export interface IWatchOptions extends IWatchOptionsWithoutCorrelation {
563
>
564
>
/**
565
>
* If provided, file change events from the watcher that
566
>
* are a result of this watch request will carry the same
567
>
* id.
568
>
*/
569
>
readonly correlationId?: number;
570
>
}
571
>
572
>
export const enum FileChangeFilter {
573
>
UPDATED = 1 << 1,
574
>
ADDED = 1 << 2,
575
>
DELETED = 1 << 3
576
>
}
577
>
578
>
export interface IWatchOptionsWithCorrelation extends IWatchOptions {
579
>
readonly correlationId: number;
580
>
}
581
>
582
>
export interface IFileSystemWatcher extends IDisposable {
583
>
584
>
/**
585
>
* An event which fires on file/folder change only for changes
586
>
* that correlate to the watch request with matching correlation
587
>
* identifier.
588
>
*/
589
>
readonly onDidChange: Event<FileChangesEvent>;
590
>
}
591
>
592
>
export function isFileSystemWatcher(thing: unknown): thing is IFileSystemWatcher {
593
const candidate = thing as IFileSystemWatcher | undefined;
594
595
return !!candidate && typeof candidate.onDidChange === 'function';
596
}
598
>
export const enum FileSystemProviderCapabilities {
599
>
600
>
/**
601
>
* No capabilities.
602
>
*/
603
>
None = 0,
604
>
605
>
/**
606
>
* Provider supports unbuffered read/write.
607
>
*/
608
>
FileReadWrite = 1 << 1,
609
>
610
>
/**
611
>
* Provider supports open/read/write/close low level file operations.
612
>
*/
613
>
FileOpenReadWriteClose = 1 << 2,
614
>
615
>
/**
616
>
* Provider supports stream based reading.
617
>
*/
618
>
FileReadStream = 1 << 4,
619
>
620
>
/**
621
>
* Provider supports copy operation.
622
>
*/
623
>
FileFolderCopy = 1 << 3,
624
>
625
>
/**
626
>
* Provider is path case sensitive.
627
>
*/
628
>
PathCaseSensitive = 1 << 10,
629
>
630
>
/**
631
>
* All files of the provider are readonly.
632
>
*/
633
>
Readonly = 1 << 11,
634
>
635
>
/**
636
>
* Provider supports to delete via trash.
637
>
*/
638
>
Trash = 1 << 12,
639
>
640
>
/**
641
>
* Provider support to unlock files for writing.
642
>
*/
643
>
FileWriteUnlock = 1 << 13,
644
>
645
>
/**
646
>
* Provider support to read files atomically. This implies the
647
>
* provider provides the `FileReadWrite` capability too.
648
>
*/
649
>
FileAtomicRead = 1 << 14,
650
>
651
>
/**
652
>
* Provider support to write files atomically. This implies the
653
>
* provider provides the `FileReadWrite` capability too.
654
>
*/
655
>
FileAtomicWrite = 1 << 15,
656
>
657
>
/**
658
>
* Provider support to delete atomically.
659
>
*/
660
>
FileAtomicDelete = 1 << 16,
661
>
662
>
/**
663
>
* Provider support to clone files atomically.
664
>
*/
665
>
FileClone = 1 << 17,
666
>
667
>
/**
668
>
* Provider support to resolve real paths.
669
>
*/
670
>
FileRealpath = 1 << 18,
671
>
672
>
/**
673
>
* Provider support to append to files.
674
>
*/
675
>
FileAppend = 1 << 19
676
>
}
677
>
678
>
export interface IFileSystemProvider {
679
>
680
>
readonly capabilities: FileSystemProviderCapabilities;
681
>
readonly onDidChangeCapabilities: Event<void>;
682
>
683
>
readonly onDidChangeFile: Event<readonly IFileChange[]>;
684
>
readonly onDidWatchError?: Event<string>;
685
>
watch(resource: URI, opts: IWatchOptions): IDisposable;
686
>
687
>
stat(resource: URI): Promise<IStat>;
688
>
mkdir(resource: URI): Promise<void>;
689
>
readdir(resource: URI): Promise<[string, FileType][]>;
690
>
delete(resource: URI, opts: IFileDeleteOptions): Promise<void>;
691
>
692
>
rename(from: URI, to: URI, opts: IFileOverwriteOptions): Promise<void>;
693
>
copy?(from: URI, to: URI, opts: IFileOverwriteOptions): Promise<void>;
694
>
695
>
readFile?(resource: URI): Promise<Uint8Array>;
696
>
writeFile?(resource: URI, content: Uint8Array, opts: IFileWriteOptions): Promise<void>;
697
>
698
>
readFileStream?(resource: URI, opts: IFileReadStreamOptions, token: CancellationToken): ReadableStreamEvents<Uint8Array>;
699
>
700
>
open?(resource: URI, opts: IFileOpenOptions): Promise<number>;
701
>
close?(fd: number): Promise<void>;
702
>
read?(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise<number>;
703
>
write?(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise<number>;
704
>
705
>
cloneFile?(from: URI, to: URI): Promise<void>;
706
>
}
707
>
708
>
export interface IFileSystemProviderWithFileReadWriteCapability extends IFileSystemProvider {
709
>
readFile(resource: URI): Promise<Uint8Array>;
710
>
writeFile(resource: URI, content: Uint8Array, opts: IFileWriteOptions): Promise<void>;
711
>
}
712
>
713
>
export function hasReadWriteCapability(provider: IFileSystemProvider): provider is IFileSystemProviderWithFileReadWriteCapability {
714
return !!(provider.capabilities & FileSystemProviderCapabilities.FileReadWrite);
715
}
717
>
export function hasFileAppendCapability(provider: IFileSystemProvider): boolean {
718
return !!(provider.capabilities & FileSystemProviderCapabilities.FileAppend);
719
}
721
>
export interface IFileSystemProviderWithFileFolderCopyCapability extends IFileSystemProvider {
722
>
copy(from: URI, to: URI, opts: IFileOverwriteOptions): Promise<void>;
723
>
}
724
>
725
>
export function hasFileFolderCopyCapability(provider: IFileSystemProvider): provider is IFileSystemProviderWithFileFolderCopyCapability {
726
return !!(provider.capabilities & FileSystemProviderCapabilities.FileFolderCopy);
727
}
729
>
export interface IFileSystemProviderWithFileCloneCapability extends IFileSystemProvider {
730
>
cloneFile(from: URI, to: URI): Promise<void>;
731
>
}
732
>
733
>
export function hasFileCloneCapability(provider: IFileSystemProvider): provider is IFileSystemProviderWithFileCloneCapability {
734
return !!(provider.capabilities & FileSystemProviderCapabilities.FileClone);
735
}
737
>
export interface IFileSystemProviderWithFileRealpathCapability extends IFileSystemProvider {
738
>
realpath(resource: URI): Promise<string>;
739
>
}
740
>
741
>
export function hasFileRealpathCapability(provider: IFileSystemProvider): provider is IFileSystemProviderWithFileRealpathCapability {
742
return !!(provider.capabilities & FileSystemProviderCapabilities.FileRealpath);
743
}
745
>
export interface IFileSystemProviderWithOpenReadWriteCloseCapability extends IFileSystemProvider {
746
>
open(resource: URI, opts: IFileOpenOptions): Promise<number>;
747
>
close(fd: number): Promise<void>;
748
>
read(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise<number>;
749
>
write(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise<number>;
750
>
}
751
>
752
>
export function hasOpenReadWriteCloseCapability(provider: IFileSystemProvider): provider is IFileSystemProviderWithOpenReadWriteCloseCapability {
753
return !!(provider.capabilities & FileSystemProviderCapabilities.FileOpenReadWriteClose);
754
}
756
>
export interface IFileSystemProviderWithFileReadStreamCapability extends IFileSystemProvider {
757
>
readFileStream(resource: URI, opts: IFileReadStreamOptions, token: CancellationToken): ReadableStreamEvents<Uint8Array>;
758
>
}
759
>
760
>
export function hasFileReadStreamCapability(provider: IFileSystemProvider): provider is IFileSystemProviderWithFileReadStreamCapability {
761
return !!(provider.capabilities & FileSystemProviderCapabilities.FileReadStream);
762
}
764
>
export interface IFileSystemProviderWithFileAtomicReadCapability extends IFileSystemProvider {
765
>
readFile(resource: URI, opts?: IFileAtomicReadOptions): Promise<Uint8Array>;
766
>
enforceAtomicReadFile?(resource: URI): boolean;
767
>
}
768
>
769
>
export function hasFileAtomicReadCapability(provider: IFileSystemProvider): provider is IFileSystemProviderWithFileAtomicReadCapability {
770
if (!hasReadWriteCapability(provider)) {
771
return false; // we require the `FileReadWrite` capability too