Skip to content

Commit

Permalink
debt - restore used class
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Mar 11, 2019
1 parent 76c330c commit d77d8d5
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/vs/platform/download/node/downloadIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
*--------------------------------------------------------------------------------------------*/

import { URI } from 'vs/base/common/uri';
import * as path from 'vs/base/common/path';
import * as fs from 'fs';
import { IServerChannel } from 'vs/base/parts/ipc/node/ipc';
import { IChannel, IServerChannel } from 'vs/base/parts/ipc/node/ipc';
import { Event, Emitter } from 'vs/base/common/event';
import { IDownloadService } from 'vs/platform/download/common/download';
import { mkdirp } from 'vs/base/node/pfs';
import { IURITransformer } from 'vs/base/common/uriIpc';
import { tmpdir } from 'os';
import { generateUuid } from 'vs/base/common/uuid';

type UploadResponse = Buffer | string | undefined;

Expand Down Expand Up @@ -35,3 +41,36 @@ export class DownloadServiceChannel implements IServerChannel {
throw new Error(`Call not found: ${command}`);
}
}

export class DownloadServiceChannelClient implements IDownloadService {

_serviceBrand: any;

constructor(private channel: IChannel, private getUriTransformer: () => IURITransformer) { }

download(from: URI, to: string = path.join(tmpdir(), generateUuid())): Promise<string> {
from = this.getUriTransformer().transformOutgoingURI(from);
const dirName = path.dirname(to);
let out: fs.WriteStream;
return new Promise<string>((c, e) => {
return mkdirp(dirName)
.then(() => {
out = fs.createWriteStream(to);
out.once('close', () => c(to));
out.once('error', e);
const uploadStream = this.channel.listen<UploadResponse>('upload', from);
const disposable = uploadStream(result => {
if (result === undefined) {
disposable.dispose();
out.end(() => c(to));
} else if (Buffer.isBuffer(result)) {
out.write(result);
} else if (typeof result === 'string') {
disposable.dispose();
out.end(() => e(result));
}
});
});
});
}
}

0 comments on commit d77d8d5

Please sign in to comment.