Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
d86affcd
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d86affcd
编写于
3月 01, 2017
作者:
K
katainaka0503
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor encoding.ts
上级
342aa319
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
30 addition
and
37 deletion
+30
-37
src/vs/base/node/encoding.ts
src/vs/base/node/encoding.ts
+12
-8
src/vs/base/test/node/encoding/encoding.test.ts
src/vs/base/test/node/encoding/encoding.test.ts
+15
-25
src/vs/workbench/services/files/node/fileService.ts
src/vs/workbench/services/files/node/fileService.ts
+1
-1
src/vs/workbench/services/files/test/node/fileService.test.ts
...vs/workbench/services/files/test/node/fileService.test.ts
+2
-3
未找到文件。
src/vs/base/node/encoding.ts
浏览文件 @
d86affcd
...
...
@@ -7,6 +7,7 @@
import
stream
=
require
(
'
vs/base/node/stream
'
);
import
iconv
=
require
(
'
iconv-lite
'
);
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
export
const
UTF8
=
'
utf8
'
;
export
const
UTF8_with_bom
=
'
utf8bom
'
;
...
...
@@ -87,14 +88,17 @@ export function detectEncodingByBOMFromBuffer(buffer: NodeBuffer, bytesRead: num
/**
* Detects the Byte Order Mark in a given file.
* If no BOM is detected,
`encoding` will be null
.
* If no BOM is detected,
null will be passed to callback
.
*/
export
function
detectEncodingByBOM
(
file
:
string
,
callback
:
(
error
:
Error
,
encoding
:
string
)
=>
void
):
void
{
stream
.
readExactlyByFile
(
file
,
3
,
(
err
:
Error
,
buffer
:
NodeBuffer
,
bytesRead
:
number
)
=>
{
if
(
err
)
{
return
callback
(
err
,
null
);
}
return
callback
(
null
,
detectEncodingByBOMFromBuffer
(
buffer
,
bytesRead
));
export
function
detectEncodingByBOM
(
file
:
string
):
TPromise
<
string
>
{
return
new
TPromise
((
complete
,
error
)
=>
{
stream
.
readExactlyByFile
(
file
,
3
,
(
err
:
Error
,
buffer
:
NodeBuffer
,
bytesRead
:
number
)
=>
{
if
(
err
)
{
error
(
err
);
}
else
{
complete
(
detectEncodingByBOMFromBuffer
(
buffer
,
bytesRead
));
}
});
});
}
\ No newline at end of file
src/vs/base/test/node/encoding/encoding.test.ts
浏览文件 @
d86affcd
...
...
@@ -10,58 +10,48 @@ import assert = require('assert');
import
encoding
=
require
(
'
vs/base/node/encoding
'
);
suite
(
'
Encoding
'
,
()
=>
{
test
(
'
detectBOM UTF-8
'
,
function
(
done
:
()
=>
void
)
{
test
(
'
detectBOM UTF-8
'
,
(
done
:
(
err
?:
any
)
=>
void
)
=>
{
const
file
=
require
.
toUrl
(
'
./fixtures/some_utf8.css
'
);
encoding
.
detectEncodingByBOM
(
file
,
(
error
:
Error
,
encoding
:
string
)
=>
{
assert
.
equal
(
error
,
null
);
encoding
.
detectEncodingByBOM
(
file
).
then
(
(
encoding
:
string
)
=>
{
assert
.
equal
(
encoding
,
'
utf8
'
);
done
();
});
}
,
done
);
});
test
(
'
detectBOM UTF-16 LE
'
,
function
(
done
:
()
=>
void
)
{
test
(
'
detectBOM UTF-16 LE
'
,
(
done
:
(
err
?:
any
)
=>
void
)
=>
{
const
file
=
require
.
toUrl
(
'
./fixtures/some_utf16le.css
'
);
encoding
.
detectEncodingByBOM
(
file
,
(
error
:
Error
,
encoding
:
string
)
=>
{
assert
.
equal
(
error
,
null
);
encoding
.
detectEncodingByBOM
(
file
).
then
((
encoding
:
string
)
=>
{
assert
.
equal
(
encoding
,
'
utf16le
'
);
done
();
});
}
,
done
);
});
test
(
'
detectBOM UTF-16 BE
'
,
function
(
done
:
()
=>
void
)
{
test
(
'
detectBOM UTF-16 BE
'
,
(
done
:
(
err
?:
any
)
=>
void
)
=>
{
const
file
=
require
.
toUrl
(
'
./fixtures/some_utf16be.css
'
);
encoding
.
detectEncodingByBOM
(
file
,
(
error
:
Error
,
encoding
:
string
)
=>
{
assert
.
equal
(
error
,
null
);
encoding
.
detectEncodingByBOM
(
file
).
then
((
encoding
:
string
)
=>
{
assert
.
equal
(
encoding
,
'
utf16be
'
);
done
();
});
}
,
done
);
});
test
(
'
detectBOM ANSI
'
,
function
(
done
:
()
=>
void
)
{
test
(
'
detectBOM ANSI
'
,
function
(
done
:
(
err
?:
any
)
=>
void
)
{
const
file
=
require
.
toUrl
(
'
./fixtures/some_ansi.css
'
);
encoding
.
detectEncodingByBOM
(
file
,
(
error
:
Error
,
encoding
:
string
)
=>
{
assert
.
equal
(
error
,
null
);
encoding
.
detectEncodingByBOM
(
file
).
then
((
encoding
:
string
)
=>
{
assert
.
equal
(
encoding
,
null
);
done
();
});
}
,
done
);
});
test
(
'
detectBOM ANSI
'
,
function
(
done
:
()
=>
void
)
{
test
(
'
detectBOM ANSI
'
,
function
(
done
:
(
err
?:
any
)
=>
void
)
{
const
file
=
require
.
toUrl
(
'
./fixtures/empty.txt
'
);
encoding
.
detectEncodingByBOM
(
file
,
(
error
:
Error
,
encoding
:
string
)
=>
{
assert
.
equal
(
error
,
null
);
encoding
.
detectEncodingByBOM
(
file
).
then
((
encoding
:
string
)
=>
{
assert
.
equal
(
encoding
,
null
);
done
();
});
}
,
done
);
});
});
src/vs/workbench/services/files/node/fileService.ts
浏览文件 @
d86affcd
...
...
@@ -300,7 +300,7 @@ export class FileService implements IFileService {
if
(
options
.
overwriteEncoding
)
{
addBomPromise
=
TPromise
.
as
(
false
);
// if we are to overwrite the encoding, we do not preserve it if found
}
else
{
addBomPromise
=
nfcall
(
encoding
.
detectEncodingByBOM
,
absolutePath
).
then
(
enc
=>
enc
===
encoding
.
UTF8
);
// otherwise preserve it if found
addBomPromise
=
encoding
.
detectEncodingByBOM
(
absolutePath
).
then
(
enc
=>
enc
===
encoding
.
UTF8
);
// otherwise preserve it if found
}
}
...
...
src/vs/workbench/services/files/test/node/fileService.test.ts
浏览文件 @
d86affcd
...
...
@@ -13,7 +13,6 @@ import assert = require('assert');
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
FileService
,
IEncodingOverride
}
from
'
vs/workbench/services/files/node/fileService
'
;
import
{
FileOperation
,
FileOperationEvent
,
FileChangesEvent
,
FileOperationResult
,
IFileOperationResult
}
from
'
vs/platform/files/common/files
'
;
import
{
nfcall
}
from
'
vs/base/common/async
'
;
import
uri
from
'
vs/base/common/uri
'
;
import
uuid
=
require
(
'
vs/base/common/uuid
'
);
import
extfs
=
require
(
'
vs/base/node/extfs
'
);
...
...
@@ -542,7 +541,7 @@ suite('FileService', () => {
c
.
encoding
=
encoding
;
return
service
.
updateContent
(
c
.
resource
,
c
.
value
,
{
encoding
:
encoding
}).
then
(
c
=>
{
return
nfcall
(
encodingLib
.
detectEncodingByBOM
,
c
.
resource
.
fsPath
).
then
((
enc
)
=>
{
return
encodingLib
.
detectEncodingByBOM
(
c
.
resource
.
fsPath
).
then
((
enc
)
=>
{
assert
.
equal
(
enc
,
encodingLib
.
UTF16be
);
return
service
.
resolveContent
(
resource
).
then
(
c
=>
{
...
...
@@ -565,7 +564,7 @@ suite('FileService', () => {
c
.
value
=
'
Some updates
'
;
return
service
.
updateContent
(
c
.
resource
,
c
.
value
,
{
encoding
:
encoding
}).
then
(
c
=>
{
return
nfcall
(
encodingLib
.
detectEncodingByBOM
,
c
.
resource
.
fsPath
).
then
((
enc
)
=>
{
return
encodingLib
.
detectEncodingByBOM
(
c
.
resource
.
fsPath
).
then
((
enc
)
=>
{
assert
.
equal
(
enc
,
encodingLib
.
UTF16le
);
return
service
.
resolveContent
(
resource
).
then
(
c
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录