diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 48cff5d1f66ca..b4ee0962bd6ff 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -19,6 +19,17 @@ declare module 'vscode' { export function changeLanguage(document: TextDocument, languageId: string): Thenable; } + //#region Joh - read/write in chunks + + export interface FileSystemProvider { + open?(resource: Uri): number | Thenable; + close?(fd: number): void | Thenable; + read?(fd: number, pos: number, data: Uint8Array, offset: number, length: number): number | Thenable; + write?(fd: number, pos: number, data: Uint8Array, offset: number, length: number): number | Thenable; + } + + //#endregion + //#region Rob: search provider /** diff --git a/src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts b/src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts index a1005d30a80d9..60985bd290202 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts @@ -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 { return this._proxy.$stat(this._handle, resource).then(undefined, err => { throw err; @@ -103,10 +107,7 @@ class RemoteFileSystemProvider implements IFileSystemProvider { } writeFile(resource: URI, content: Uint8Array, opts: FileWriteOptions): TPromise { - 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 { @@ -128,4 +129,20 @@ class RemoteFileSystemProvider implements IFileSystemProvider { copy(resource: URI, target: URI, opts: FileOverwriteOptions): TPromise { return this._proxy.$copy(this._handle, resource, target, opts); } + + open(resource: URI): TPromise { + return this._proxy.$open(this._handle, resource); + } + + close(fd: number): TPromise { + return this._proxy.$close(this._handle, fd); + } + + read(fd: number, pos: number, data: Uint8Array, offset: number, length: number): TPromise { + 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 { + return this._proxy.$write(this._handle, fd, pos, RemoteFileSystemProvider._asBuffer(data), offset, length); + } } diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 49421a3b34131..bc70721284e3e 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -691,6 +691,10 @@ export interface ExtHostFileSystemShape { $delete(handle: number, resource: UriComponents, opts: FileDeleteOptions): TPromise; $watch(handle: number, session: number, resource: UriComponents, opts: IWatchOptions): void; $unwatch(handle: number, session: number): void; + $open(handle: number, resource: UriComponents): TPromise; + $close(handle: number, fd: number): TPromise; + $read(handle: number, fd: number, pos: number, data: Buffer, offset: number, length: number): TPromise; + $write(handle: number, fd: number, pos: number, data: Buffer, offset: number, length: number): TPromise; } export interface ExtHostSearchShape { diff --git a/src/vs/workbench/api/node/extHostFileSystem.ts b/src/vs/workbench/api/node/extHostFileSystem.ts index 1b4e15972f086..6faf26d9b3d7d 100644 --- a/src/vs/workbench/api/node/extHostFileSystem.ts +++ b/src/vs/workbench/api/node/extHostFileSystem.ts @@ -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); @@ -201,4 +206,21 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape { this._watches.delete(session); } } + + $open(handle: number, resource: UriComponents): TPromise { + return asWinJsPromise(() => this._fsProvider.get(handle).open(URI.revive(resource))); + } + + $close(handle: number, fd: number): TPromise { + return asWinJsPromise(() => this._fsProvider.get(handle).close(fd)); + } + + $read(handle: number, fd: number, pos: number, data: Buffer, offset: number, length: number): TPromise { + 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 { + return asWinJsPromise(() => this._fsProvider.get(handle).write(fd, pos, data, offset, length)); + } + }