src/vs/workbench/contrib/files/browser/fileImportExport.ts/FileDownload/downloadFileBufferedBrowser
class FileDownload:	private async downloadFileBufferedBrowser(resource: URI, target: FileSystemWritableFileStream, operation: IDownloadOperation, token: CancellationToken): Promise<void> {
		const contents = await this.fileService.readFileStream(resource);
		if (token.isCancellationRequested) {
			target.close();
			return;
		}

		return new Promise<void>((resolve, reject) => {
			const sourceStream = contents.value;

			const disposables = new DisposableStore();
			disposables.add(toDisposable(() => target.close()));

			let disposed = false;
			disposables.add(toDisposable(() => disposed = true));

			disposables.add(once(token.onCancellationRequested)(() => {
				disposables.dispose();
				reject();
			}));

			listenStream(sourceStream, {
				onData: data => {
					if (!disposed) {
						target.write(data.buffer);
						this.reportProgress(contents.name, contents.size, data.byteLength, operation);
					}
				},
				onError: error => {
					disposables.dispose();
					reject(error);
				},
				onEnd: () => {
					disposables.dispose();
					resolve();
				}
			});
		});
	}