File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -95,17 +95,12 @@ export function detectEncodingByBOM(file: string): TPromise<string> {
9595}
9696
9797const MINIMUM_THRESHOLD = 0.2 ;
98-
9998const IGNORE_ENCODINGS = [ 'ascii' , 'utf-8' , 'utf-16' , 'utf-32' ] ;
100- const MAPPED_ENCODINGS : { [ name : string ] : string } = {
101- 'ibm866' : 'cp866'
102- } ;
10399
104100/**
105101 * Guesses the encoding from buffer.
106102 */
107103export async function guessEncodingByBuffer ( buffer : NodeBuffer ) : TPromise < string > {
108-
109104 const jschardet = await import ( 'jschardet' ) ;
110105
111106 jschardet . Constants . MINIMUM_THRESHOLD = MINIMUM_THRESHOLD ;
@@ -126,9 +121,14 @@ export async function guessEncodingByBuffer(buffer: NodeBuffer): TPromise<string
126121 return toIconvLiteEncoding ( guessed . encoding ) ;
127122}
128123
124+ const JSCHARDET_TO_ICONV_ENCODINGS : { [ name : string ] : string } = {
125+ 'ibm866' : 'cp866' ,
126+ 'big5' : 'cp950'
127+ } ;
128+
129129function toIconvLiteEncoding ( encodingName : string ) : string {
130130 const normalizedEncodingName = encodingName . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, '' ) . toLowerCase ( ) ;
131- const mapped = MAPPED_ENCODINGS [ normalizedEncodingName ] ;
131+ const mapped = JSCHARDET_TO_ICONV_ENCODINGS [ normalizedEncodingName ] ;
132132
133133 return mapped || normalizedEncodingName ;
134134}
You can’t perform that action at this time.
0 commit comments