提交 59db5a57 编写于 作者: S Sandeep Somavarapu

use toVSBufferReadableStream

上级 bfc98d6b
......@@ -164,23 +164,27 @@ export interface ReadableStream<T> {
/**
* Stops emitting any events until resume() is called.
*/
pause(): void;
pause?(): void;
/**
* Starts emitting events again after pause() was called.
*/
resume(): void;
resume?(): void;
/**
* Destroys the stream and stops emitting any event.
*/
destroy(): void;
destroy?(): void;
}
/**
* A readable stream that sends data via VSBuffer.
*/
export interface VSBufferReadableStream extends ReadableStream<VSBuffer> { }
export interface VSBufferReadableStream extends ReadableStream<VSBuffer> {
pause(): void;
resume(): void;
destroy(): void;
}
export function isVSBufferReadableStream(obj: any): obj is VSBufferReadableStream {
const candidate: VSBufferReadableStream = obj;
......@@ -248,10 +252,10 @@ export function bufferToStream(buffer: VSBuffer): VSBufferReadableStream {
/**
* Helper to create a VSBufferStream from a Uint8Array stream.
*/
export function toVSBufferReadableStream(stream: ReadableStream<Uint8Array>): VSBufferReadableStream {
export function toVSBufferReadableStream(stream: ReadableStream<Uint8Array | string>): VSBufferReadableStream {
const vsbufferStream = writeableBufferStream();
stream.on('data', data => vsbufferStream.write(VSBuffer.wrap(data)));
stream.on('data', data => vsbufferStream.write(typeof data === 'string' ? VSBuffer.fromString(data) : VSBuffer.wrap(data)));
stream.on('end', () => vsbufferStream.end());
stream.on('error', error => vsbufferStream.error(error));
......
......@@ -17,7 +17,7 @@ import { IRequestOptions, IRequestContext, IRequestService, IHTTPConfiguration }
import { getProxyAgent, Agent } from 'vs/platform/request/node/proxy';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ILogService } from 'vs/platform/log/common/log';
import { VSBuffer, VSBufferWriteableStream, writeableBufferStream } from 'vs/base/common/buffer';
import { toVSBufferReadableStream } from 'vs/base/common/buffer';
export interface IRawRequestFunction {
(options: http.RequestOptions, callback?: (res: http.IncomingMessage) => void): http.ClientRequest;
......@@ -111,18 +111,13 @@ export class RequestService extends Disposable implements IRequestService {
followRedirects: followRedirects - 1
}), token).then(c, e);
} else {
let _stream: Stream = res;
let stream: Stream = res;
if (res.headers['content-encoding'] === 'gzip') {
_stream = _stream.pipe(createGunzip());
stream = stream.pipe(createGunzip());
}
const stream: VSBufferWriteableStream = writeableBufferStream();
_stream.on('data', (d: string) => stream.write(VSBuffer.fromString(d)));
_stream.on('error', e => stream.end(e));
_stream.on('end', e => stream.end());
c({ res, stream } as IRequestContext);
c({ res, stream: toVSBufferReadableStream(stream) } as IRequestContext);
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册