@@ -9,9 +9,11 @@ import { Promise, TPromise } from 'vs/base/common/winjs.base';
99import { isBoolean } from 'vs/base/common/types' ;
1010import https = require( 'https' ) ;
1111import http = require( 'http' ) ;
12+ import { Stream } from 'stream' ;
1213import { parse as parseUrl } from 'url' ;
1314import { createWriteStream } from 'fs' ;
1415import { assign } from 'vs/base/common/objects' ;
16+ import { createGunzip } from 'zlib' ;
1517
1618export interface IRequestOptions {
1719 type ?: string ;
@@ -29,6 +31,7 @@ export interface IRequestOptions {
2931export interface IRequestResult {
3032 req : http . ClientRequest ;
3133 res : http . ClientResponse ;
34+ stream : Stream ;
3235}
3336
3437export function request ( options : IRequestOptions ) : TPromise < IRequestResult > {
@@ -59,7 +62,13 @@ export function request(options: IRequestOptions): TPromise<IRequestResult> {
5962 followRedirects : options . followRedirects - 1
6063 } ) ) ) ;
6164 } else {
62- c ( { req, res } ) ;
65+ let stream : Stream = res ;
66+
67+ if ( res . headers [ 'content-encoding' ] === 'gzip' ) {
68+ stream = stream . pipe ( createGunzip ( ) ) ;
69+ }
70+
71+ c ( { req, res, stream } ) ;
6372 }
6473 } ) ;
6574 req . on ( 'error' , e ) ;
@@ -81,8 +90,8 @@ export function download(filePath: string, opts: IRequestOptions): TPromise<void
8190 let out = createWriteStream ( filePath ) ;
8291
8392 out . once ( 'finish' , ( ) => c ( null ) ) ;
84- pair . res . once ( 'error' , e ) ;
85- pair . res . pipe ( out ) ;
93+ pair . stream . once ( 'error' , e ) ;
94+ pair . stream . pipe ( out ) ;
8695 } ) ) ;
8796}
8897
@@ -97,9 +106,9 @@ export function text(opts: IRequestOptions): TPromise<string> {
97106 }
98107
99108 let buffer : string [ ] = [ ] ;
100- pair . res . on ( 'data' , d => buffer . push ( d ) ) ;
101- pair . res . on ( 'end' , ( ) => c ( buffer . join ( '' ) ) ) ;
102- pair . res . on ( 'error' , e ) ;
109+ pair . stream . on ( 'data' , d => buffer . push ( d ) ) ;
110+ pair . stream . on ( 'end' , ( ) => c ( buffer . join ( '' ) ) ) ;
111+ pair . stream . on ( 'error' , e ) ;
103112 } ) ) ;
104113}
105114
@@ -118,8 +127,8 @@ export function json<T>(opts: IRequestOptions): TPromise<T> {
118127 }
119128
120129 let buffer : string [ ] = [ ] ;
121- pair . res . on ( 'data' , d => buffer . push ( d ) ) ;
122- pair . res . on ( 'end' , ( ) => c ( JSON . parse ( buffer . join ( '' ) ) ) ) ;
123- pair . res . on ( 'error' , e ) ;
130+ pair . stream . on ( 'data' , d => buffer . push ( d ) ) ;
131+ pair . stream . on ( 'end' , ( ) => c ( JSON . parse ( buffer . join ( '' ) ) ) ) ;
132+ pair . stream . on ( 'error' , e ) ;
124133 } ) ) ;
125134}
0 commit comments