@@ -26,7 +26,7 @@ import * as iconv from 'iconv-lite';
2626import { File } from '../lib/node-utility/File' ;
2727import * as fs from 'fs' ;
2828
29- export enum CodeType {
29+ export enum EncodingType {
3030 UTF8 = 'utf8' ,
3131 UNICODE = 'unicode' ,
3232 UTF16BE = 'utf16be' ,
@@ -36,7 +36,7 @@ export enum CodeType {
3636 NULL = 'null'
3737}
3838
39- export class CodeConverter {
39+ export class EncodingConverter {
4040
4141 static trimUtf8BomHeader ( str : string | Buffer ) : string {
4242
@@ -58,73 +58,73 @@ export class CodeConverter {
5858 return str ;
5959 }
6060
61- private static getCodeType ( bomHead : Buffer ) : CodeType {
61+ private static getCodeType ( bomHead : Buffer ) : EncodingType {
6262
63- let codeType : CodeType ;
63+ let codeType : EncodingType ;
6464
6565 if ( bomHead && bomHead . length === 4 ) {
6666
6767 switch ( bomHead [ 0 ] ) {
6868 case 0xfe :
6969 if ( bomHead [ 1 ] === 0xff ) {
70- codeType = CodeType . UTF16BE ;
70+ codeType = EncodingType . UTF16BE ;
7171 }
7272 else {
73- codeType = CodeType . NULL ;
73+ codeType = EncodingType . NULL ;
7474 }
7575 break ;
7676 case 0xef :
7777 if ( bomHead [ 1 ] === 0xbb && bomHead [ 2 ] === 0xbf ) {
78- codeType = CodeType . UTF8 ;
78+ codeType = EncodingType . UTF8 ;
7979 }
8080 else {
81- codeType = CodeType . NULL ;
81+ codeType = EncodingType . NULL ;
8282 }
8383 break ;
8484 case 0x00 :
8585 if ( bomHead [ 1 ] === 0x00 && bomHead [ 2 ] === 0xfe && bomHead [ 3 ] === 0xff ) {
86- codeType = CodeType . UTF32BE ;
86+ codeType = EncodingType . UTF32BE ;
8787 }
8888 else {
89- codeType = CodeType . NULL ;
89+ codeType = EncodingType . NULL ;
9090 }
9191 break ;
9292 case 0xff :
9393 if ( bomHead [ 1 ] === 0xfe && bomHead [ 2 ] === 0x00 && bomHead [ 3 ] === 0x00 ) {
94- codeType = CodeType . UTF32LE ;
94+ codeType = EncodingType . UTF32LE ;
9595 }
9696 else if ( bomHead [ 1 ] === 0xfe ) {
97- codeType = CodeType . UNICODE ;
97+ codeType = EncodingType . UNICODE ;
9898 }
9999 else {
100- codeType = CodeType . NULL ;
100+ codeType = EncodingType . NULL ;
101101 }
102102 break ;
103103 default :
104- codeType = CodeType . ASCII ;
104+ codeType = EncodingType . ASCII ;
105105 break ;
106106 }
107107 } else {
108- codeType = codeType = CodeType . NULL ;
108+ codeType = codeType = EncodingType . NULL ;
109109 }
110110
111111 return codeType ;
112112 }
113113
114- static getFileCodeType ( file : File ) : Promise < CodeType > {
114+ static getFileCodeType ( file : File ) : Promise < EncodingType > {
115115 return new Promise ( ( resolve ) => {
116116 const stream = fs . createReadStream ( file . path ) ;
117117 stream . on ( 'readable' , ( ) => {
118118 let bomHead : Buffer = stream . read ( 4 ) ;
119119 stream . close ( ) ;
120- resolve ( CodeConverter . getCodeType ( bomHead ) ) ;
120+ resolve ( EncodingConverter . getCodeType ( bomHead ) ) ;
121121 } ) ;
122122 } ) ;
123123 }
124124
125- static getCodeTypeSync ( file : File ) : CodeType {
125+ static getCodeTypeSync ( file : File ) : EncodingType {
126126 const buf = fs . readFileSync ( file . path ) ;
127- return CodeConverter . getCodeType ( buf ) ;
127+ return EncodingConverter . getCodeType ( buf ) ;
128128 }
129129
130130 static existCode ( encoding : string ) : boolean {
0 commit comments