Skip to content

Commit

Permalink
add proposed api for file system open/close and read/write, #41985
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Sep 4, 2018
1 parent e5a1664 commit fa5922b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ declare module 'vscode' {
export function changeLanguage(document: TextDocument, languageId: string): Thenable<void>;
}

//#region Joh - read/write in chunks

export interface FileSystemProvider {
open?(resource: Uri): number | Thenable<number>;
close?(fd: number): void | Thenable<void>;
read?(fd: number, pos: number, data: Uint8Array, offset: number, length: number): number | Thenable<number>;
write?(fd: number, pos: number, data: Uint8Array, offset: number, length: number): number | Thenable<number>;
}

//#endregion

//#region Rob: search provider

/**
Expand Down
25 changes: 21 additions & 4 deletions src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class RemoteFileSystemProvider implements IFileSystemProvider {

// --- forwarding calls

private static _asBuffer(data: Uint8Array): Buffer {
return Buffer.isBuffer(data) ? data : Buffer.from(data.buffer, data.byteOffset, data.byteLength);
}

stat(resource: URI): TPromise<IStat> {
return this._proxy.$stat(this._handle, resource).then(undefined, err => {
throw err;
Expand All @@ -103,10 +107,7 @@ class RemoteFileSystemProvider implements IFileSystemProvider {
}

writeFile(resource: URI, content: Uint8Array, opts: FileWriteOptions): TPromise<void> {
let encoded = Buffer.isBuffer(content)
? content
: Buffer.from(content.buffer, content.byteOffset, content.byteLength);
return this._proxy.$writeFile(this._handle, resource, encoded, opts);
return this._proxy.$writeFile(this._handle, resource, RemoteFileSystemProvider._asBuffer(content), opts);
}

delete(resource: URI, opts: FileDeleteOptions): TPromise<void> {
Expand All @@ -128,4 +129,20 @@ class RemoteFileSystemProvider implements IFileSystemProvider {
copy(resource: URI, target: URI, opts: FileOverwriteOptions): TPromise<void> {
return this._proxy.$copy(this._handle, resource, target, opts);
}

open(resource: URI): TPromise<number> {
return this._proxy.$open(this._handle, resource);
}

close(fd: number): TPromise<void> {
return this._proxy.$close(this._handle, fd);
}

read(fd: number, pos: number, data: Uint8Array, offset: number, length: number): TPromise<number> {
return this._proxy.$read(this._handle, fd, pos, RemoteFileSystemProvider._asBuffer(data), offset, length);
}

write(fd: number, pos: number, data: Uint8Array, offset: number, length: number): TPromise<number> {
return this._proxy.$write(this._handle, fd, pos, RemoteFileSystemProvider._asBuffer(data), offset, length);
}
}
4 changes: 4 additions & 0 deletions src/vs/workbench/api/node/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,10 @@ export interface ExtHostFileSystemShape {
$delete(handle: number, resource: UriComponents, opts: FileDeleteOptions): TPromise<void>;
$watch(handle: number, session: number, resource: UriComponents, opts: IWatchOptions): void;
$unwatch(handle: number, session: number): void;
$open(handle: number, resource: UriComponents): TPromise<number>;
$close(handle: number, fd: number): TPromise<void>;
$read(handle: number, fd: number, pos: number, data: Buffer, offset: number, length: number): TPromise<number>;
$write(handle: number, fd: number, pos: number, data: Buffer, offset: number, length: number): TPromise<number>;
}

export interface ExtHostSearchShape {
Expand Down
22 changes: 22 additions & 0 deletions src/vs/workbench/api/node/extHostFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
if (typeof provider.copy === 'function') {
capabilites += files.FileSystemProviderCapabilities.FileFolderCopy;
}
if (typeof provider.open === 'function' && typeof provider.close === 'function'
&& typeof provider.read === 'function' && typeof provider.write === 'function'
) {
capabilites += files.FileSystemProviderCapabilities.FileOpenReadWriteClose;
}

this._proxy.$registerFileSystemProvider(handle, scheme, capabilites);

Expand Down Expand Up @@ -201,4 +206,21 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
this._watches.delete(session);
}
}

$open(handle: number, resource: UriComponents): TPromise<number> {
return asWinJsPromise(() => this._fsProvider.get(handle).open(URI.revive(resource)));
}

$close(handle: number, fd: number): TPromise<void> {
return asWinJsPromise(() => this._fsProvider.get(handle).close(fd));
}

$read(handle: number, fd: number, pos: number, data: Buffer, offset: number, length: number): TPromise<number> {
return asWinJsPromise(() => this._fsProvider.get(handle).read(fd, pos, data, offset, length));
}

$write(handle: number, fd: number, pos: number, data: Buffer, offset: number, length: number): TPromise<number> {
return asWinJsPromise(() => this._fsProvider.get(handle).write(fd, pos, data, offset, length));
}

}

0 comments on commit fa5922b

Please sign in to comment.