55
66import * as stream from 'vs/base/node/stream' ;
77import * as iconv from 'iconv-lite' ;
8- import { TPromise } from 'vs/base/common/winjs.base' ;
98import { isLinux , isMacintosh } from 'vs/base/common/platform' ;
109import { exec } from 'child_process' ;
1110import { Readable , Writable , WritableOptions } from 'stream' ;
@@ -21,8 +20,7 @@ export interface IDecodeStreamOptions {
2120 overwriteEncoding ?( detectedEncoding : string ) : string ;
2221}
2322
24- export function toDecodeStream ( readable : Readable , options : IDecodeStreamOptions ) : TPromise < { detected : IDetectedEncodingResult , stream : NodeJS . ReadableStream } > {
25-
23+ export function toDecodeStream ( readable : Readable , options : IDecodeStreamOptions ) : Promise < { detected : IDetectedEncodingResult , stream : NodeJS . ReadableStream } > {
2624 if ( ! options . minBytesRequiredForDetection ) {
2725 options . minBytesRequiredForDetection = options . guessEncoding ? AUTO_GUESS_BUFFER_MAX_LEN : NO_GUESS_BUFFER_MAX_LEN ;
2826 }
@@ -31,7 +29,7 @@ export function toDecodeStream(readable: Readable, options: IDecodeStreamOptions
3129 options . overwriteEncoding = detected => detected || UTF8 ;
3230 }
3331
34- return new TPromise < { detected : IDetectedEncodingResult , stream : NodeJS . ReadableStream } > ( ( resolve , reject ) => {
32+ return new Promise < { detected : IDetectedEncodingResult , stream : NodeJS . ReadableStream } > ( ( resolve , reject ) => {
3533 readable . pipe ( new class extends Writable {
3634
3735 private _decodeStream : NodeJS . ReadWriteStream ;
@@ -74,7 +72,7 @@ export function toDecodeStream(readable: Readable, options: IDecodeStreamOptions
7472
7573 _startDecodeStream ( callback : Function ) : void {
7674
77- this . _decodeStreamConstruction = TPromise . as ( detectEncodingFromBuffer ( {
75+ this . _decodeStreamConstruction = Promise . resolve ( detectEncodingFromBuffer ( {
7876 buffer : Buffer . concat ( this . _buffer ) , bytesRead : this . _bytesBuffered
7977 } , options . guessEncoding ) ) . then ( detected => {
8078 detected . encoding = options . overwriteEncoding ( detected . encoding ) ;
@@ -180,7 +178,7 @@ export function detectEncodingByBOMFromBuffer(buffer: Buffer, bytesRead: number)
180178 * Detects the Byte Order Mark in a given file.
181179 * If no BOM is detected, null will be passed to callback.
182180 */
183- export function detectEncodingByBOM ( file : string ) : TPromise < string > {
181+ export function detectEncodingByBOM ( file : string ) : Promise < string > {
184182 return stream . readExactlyByFile ( file , 3 ) . then ( ( { buffer, bytesRead } ) => detectEncodingByBOMFromBuffer ( buffer , bytesRead ) ) ;
185183}
186184
@@ -190,8 +188,8 @@ const IGNORE_ENCODINGS = ['ascii', 'utf-8', 'utf-16', 'utf-32'];
190188/**
191189 * Guesses the encoding from buffer.
192190 */
193- export function guessEncodingByBuffer ( buffer : Buffer ) : TPromise < string > {
194- return TPromise . wrap ( import ( 'jschardet' ) ) . then ( jschardet => {
191+ export function guessEncodingByBuffer ( buffer : Buffer ) : Promise < string > {
192+ return import ( 'jschardet' ) . then ( jschardet => {
195193 jschardet . Constants . MINIMUM_THRESHOLD = MINIMUM_THRESHOLD ;
196194
197195 const guessed = jschardet . detect ( buffer ) ;
@@ -270,8 +268,8 @@ export interface IDetectedEncodingResult {
270268}
271269
272270export function detectEncodingFromBuffer ( readResult : stream . ReadResult , autoGuessEncoding ?: false ) : IDetectedEncodingResult ;
273- export function detectEncodingFromBuffer ( readResult : stream . ReadResult , autoGuessEncoding ?: boolean ) : TPromise < IDetectedEncodingResult > ;
274- export function detectEncodingFromBuffer ( { buffer, bytesRead } : stream . ReadResult , autoGuessEncoding ?: boolean ) : TPromise < IDetectedEncodingResult > | IDetectedEncodingResult {
271+ export function detectEncodingFromBuffer ( readResult : stream . ReadResult , autoGuessEncoding ?: boolean ) : Promise < IDetectedEncodingResult > ;
272+ export function detectEncodingFromBuffer ( { buffer, bytesRead } : stream . ReadResult , autoGuessEncoding ?: boolean ) : Promise < IDetectedEncodingResult > | IDetectedEncodingResult {
275273
276274 // Always first check for BOM to find out about encoding
277275 let encoding = detectEncodingByBOMFromBuffer ( buffer , bytesRead ) ;
@@ -356,8 +354,8 @@ const windowsTerminalEncodings = {
356354 '1252' : 'cp1252' // West European Latin
357355} ;
358356
359- export function resolveTerminalEncoding ( verbose ?: boolean ) : TPromise < string > {
360- let rawEncodingPromise : TPromise < string > ;
357+ export function resolveTerminalEncoding ( verbose ?: boolean ) : Promise < string > {
358+ let rawEncodingPromise : Promise < string > ;
361359
362360 // Support a global environment variable to win over other mechanics
363361 const cliEncodingEnv = process . env [ 'VSCODE_CLI_ENCODING' ] ;
@@ -366,23 +364,23 @@ export function resolveTerminalEncoding(verbose?: boolean): TPromise<string> {
366364 console . log ( `Found VSCODE_CLI_ENCODING variable: ${ cliEncodingEnv } ` ) ;
367365 }
368366
369- rawEncodingPromise = TPromise . as ( cliEncodingEnv ) ;
367+ rawEncodingPromise = Promise . resolve ( cliEncodingEnv ) ;
370368 }
371369
372370 // Linux/Mac: use "locale charmap" command
373371 else if ( isLinux || isMacintosh ) {
374- rawEncodingPromise = new TPromise < string > ( c => {
372+ rawEncodingPromise = new Promise < string > ( resolve => {
375373 if ( verbose ) {
376374 console . log ( 'Running "locale charmap" to detect terminal encoding...' ) ;
377375 }
378376
379- exec ( 'locale charmap' , ( err , stdout , stderr ) => c ( stdout ) ) ;
377+ exec ( 'locale charmap' , ( err , stdout , stderr ) => resolve ( stdout ) ) ;
380378 } ) ;
381379 }
382380
383381 // Windows: educated guess
384382 else {
385- rawEncodingPromise = new TPromise < string > ( c => {
383+ rawEncodingPromise = new Promise < string > ( resolve => {
386384 if ( verbose ) {
387385 console . log ( 'Running "chcp" to detect terminal encoding...' ) ;
388386 }
@@ -393,12 +391,12 @@ export function resolveTerminalEncoding(verbose?: boolean): TPromise<string> {
393391 for ( let i = 0 ; i < windowsTerminalEncodingKeys . length ; i ++ ) {
394392 const key = windowsTerminalEncodingKeys [ i ] ;
395393 if ( stdout . indexOf ( key ) >= 0 ) {
396- return c ( windowsTerminalEncodings [ key ] ) ;
394+ return resolve ( windowsTerminalEncodings [ key ] ) ;
397395 }
398396 }
399397 }
400398
401- return c ( void 0 ) ;
399+ return resolve ( void 0 ) ;
402400 } ) ;
403401 } ) ;
404402 }
0 commit comments