Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
609d845c
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,发现更多精彩内容 >>
提交
609d845c
编写于
12月 21, 2015
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid 3x file size memory pressure when resolving file contents (fixes #1117)
上级
c4e19af9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
48 addition
and
19 deletion
+48
-19
src/typings/iconv-lite.d.ts
src/typings/iconv-lite.d.ts
+2
-2
src/vs/workbench/services/files/node/fileService.ts
src/vs/workbench/services/files/node/fileService.ts
+30
-11
src/vs/workbench/services/files/test/node/fileService.test.ts
...vs/workbench/services/files/test/node/fileService.test.ts
+16
-6
未找到文件。
src/typings/iconv-lite.d.ts
浏览文件 @
609d845c
...
...
@@ -12,7 +12,7 @@ declare module 'iconv-lite' {
export
function
encodingExists
(
encoding
:
string
):
boolean
;
export
function
decodeStream
(
encoding
:
string
):
NodeJS
.
EventEmitter
;
export
function
decodeStream
(
encoding
:
string
):
NodeJS
.
ReadWriteStream
;
export
function
encodeStream
(
encoding
:
string
):
NodeJS
.
EventEmitter
;
export
function
encodeStream
(
encoding
:
string
):
NodeJS
.
ReadWriteStream
;
}
\ No newline at end of file
src/vs/workbench/services/files/node/fileService.ts
浏览文件 @
609d845c
...
...
@@ -21,7 +21,7 @@ import {Promise, TPromise} from 'vs/base/common/winjs.base';
import
types
=
require
(
'
vs/base/common/types
'
);
import
objects
=
require
(
'
vs/base/common/objects
'
);
import
extfs
=
require
(
'
vs/base/node/extfs
'
);
import
{
nfcall
,
Limiter
,
ThrottledDelayer
}
from
'
vs/base/common/async
'
;
import
{
nfcall
,
Limiter
,
ThrottledDelayer
}
from
'
vs/base/common/async
'
;
import
uri
from
'
vs/base/common/uri
'
;
import
nls
=
require
(
'
vs/nls
'
);
...
...
@@ -212,7 +212,7 @@ export class FileService implements files.IFileService {
});
}
public
updateContent
(
resource
:
uri
,
value
:
string
,
options
:
files
.
IUpdateContentOptions
=
Object
.
create
(
null
)):
TPromise
<
files
.
IFileStat
>
{
public
updateContent
(
resource
:
uri
,
value
:
string
,
options
:
files
.
IUpdateContentOptions
=
Object
.
create
(
null
)):
TPromise
<
files
.
IFileStat
>
{
let
absolutePath
=
this
.
toAbsolutePath
(
resource
);
// 1.) check file
...
...
@@ -359,7 +359,7 @@ export class FileService implements files.IFileService {
return
this
.
doMoveOrCopyFile
(
sourcePath
,
targetPath
,
true
,
true
).
then
((
exists
)
=>
{
// 3.) resolve
return
this
.
resolve
(
targetResource
).
then
((
stat
)
=>
<
files
.
IImportResult
>
{
isNew
:
!
exists
,
stat
:
stat
});
return
this
.
resolve
(
targetResource
).
then
((
stat
)
=>
<
files
.
IImportResult
>
{
isNew
:
!
exists
,
stat
:
stat
});
});
});
}
...
...
@@ -372,7 +372,7 @@ export class FileService implements files.IFileService {
// Helpers
private
toAbsolutePath
(
arg1
:
uri
|
files
.
IFileStat
):
string
{
private
toAbsolutePath
(
arg1
:
uri
|
files
.
IFileStat
):
string
{
let
resource
:
uri
;
if
(
uri
.
isURI
(
arg1
))
{
resource
=
<
uri
>
arg1
;
...
...
@@ -419,15 +419,34 @@ export class FileService implements files.IFileService {
}
// 2.) read contents
return
pfs
.
readFile
(
absolutePath
).
then
((
contents
:
NodeBuffer
)
=>
{
return
new
Promise
((
c
,
e
)
=>
{
let
done
=
false
;
let
chunks
:
NodeBuffer
[]
=
[];
let
fileEncoding
=
this
.
getEncoding
(
model
.
resource
,
enc
);
// Handle encoding
let
content
:
files
.
IContent
=
<
any
>
model
;
content
.
value
=
iconv
.
decode
(
contents
,
fileEncoding
);
// decode takes care of stripping any BOMs from the file content
content
.
charset
=
fileEncoding
;
// make sure to store the charset in the model to restore it later when writing
const
reader
=
fs
.
createReadStream
(
absolutePath
).
pipe
(
iconv
.
decodeStream
(
fileEncoding
));
// decode takes care of stripping any BOMs from the file content
return
content
;
reader
.
on
(
'
data
'
,
(
buf
)
=>
{
chunks
.
push
(
buf
);
});
reader
.
on
(
'
error
'
,
(
error
)
=>
{
if
(
!
done
)
{
done
=
true
;
e
(
error
);
}
});
reader
.
on
(
'
end
'
,
()
=>
{
let
content
:
files
.
IContent
=
<
any
>
model
;
content
.
value
=
chunks
.
join
(
''
);
content
.
charset
=
fileEncoding
;
// make sure to store the charset in the model to restore it later when writing
if
(
!
done
)
{
done
=
true
;
c
(
content
);
}
})
});
});
}
...
...
@@ -467,7 +486,7 @@ export class FileService implements files.IFileService {
return
null
;
}
private
checkFile
(
absolutePath
:
string
,
options
:
files
.
IUpdateContentOptions
):
TPromise
<
boolean
/* exists */
>
{
private
checkFile
(
absolutePath
:
string
,
options
:
files
.
IUpdateContentOptions
):
TPromise
<
boolean
/* exists */
>
{
return
pfs
.
exists
(
absolutePath
).
then
((
exists
)
=>
{
if
(
exists
)
{
return
pfs
.
stat
(
absolutePath
).
then
((
stat
:
fs
.
Stats
)
=>
{
...
...
src/vs/workbench/services/files/test/node/fileService.test.ts
浏览文件 @
609d845c
...
...
@@ -12,9 +12,11 @@ import assert = require('assert');
import
{
FileService
,
IEncodingOverride
}
from
'
vs/workbench/services/files/node/fileService
'
;
import
{
EventType
,
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
'
);
import
encoding
=
require
(
'
vs/base/node/encoding
'
);
import
{
EventEmitter
}
from
'
vs/base/common/eventEmitter
'
;
import
utils
=
require
(
'
vs/workbench/services/files/test/node/utils
'
);
...
...
@@ -281,10 +283,14 @@ suite('FileService', () => {
c
.
charset
=
charset
;
return
service
.
updateContent
(
c
.
resource
,
c
.
value
,
{
charset
:
charset
}).
then
(
c
=>
{
return
service
.
resolveContent
(
resource
).
then
(
c
=>
{
assert
.
equal
(
c
.
charset
,
charset
);
return
nfcall
(
encoding
.
detectEncodingByBOM
,
c
.
resource
.
fsPath
).
then
((
enc
)
=>
{
assert
.
equal
(
enc
,
encoding
.
UTF16be
);
done
();
return
service
.
resolveContent
(
resource
).
then
(
c
=>
{
assert
.
equal
(
c
.
charset
,
charset
);
done
();
});
});
});
});
...
...
@@ -300,10 +306,14 @@ suite('FileService', () => {
c
.
value
=
'
Some updates
'
;
return
service
.
updateContent
(
c
.
resource
,
c
.
value
,
{
charset
:
charset
}).
then
(
c
=>
{
return
service
.
resolveContent
(
resource
).
then
(
c
=>
{
assert
.
equal
(
c
.
charset
,
charset
);
return
nfcall
(
encoding
.
detectEncodingByBOM
,
c
.
resource
.
fsPath
).
then
((
enc
)
=>
{
assert
.
equal
(
enc
,
encoding
.
UTF16le
);
done
();
return
service
.
resolveContent
(
resource
).
then
(
c
=>
{
assert
.
equal
(
c
.
charset
,
charset
);
done
();
});
});
});
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录