Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
0962b241
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,发现更多精彩内容 >>
提交
0962b241
编写于
9月 22, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
read most of the encoding from stream
上级
6dc90eac
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
66 addition
and
19 deletion
+66
-19
src/vs/base/node/mime.ts
src/vs/base/node/mime.ts
+1
-1
src/vs/workbench/services/files/electron-browser/remoteFileService.ts
...ench/services/files/electron-browser/remoteFileService.ts
+65
-18
未找到文件。
src/vs/base/node/mime.ts
浏览文件 @
0962b241
...
...
@@ -56,7 +56,7 @@ const ZERO_BYTE_DETECTION_BUFFER_MAX_LEN = 512; // number of bytes to look at to
const
NO_GUESS_BUFFER_MAX_LEN
=
512
;
// when not auto guessing the encoding, small number of bytes are enough
const
AUTO_GUESS_BUFFER_MAX_LEN
=
512
*
8
;
// with auto guessing we want a lot more content to be read for guessing
function
maxBufferLen
(
arg1
?:
DetectMimesOption
|
boolean
):
number
{
export
function
maxBufferLen
(
arg1
?:
DetectMimesOption
|
boolean
):
number
{
let
autoGuessEncoding
:
boolean
;
if
(
typeof
arg1
===
'
boolean
'
)
{
autoGuessEncoding
=
arg1
;
...
...
src/vs/workbench/services/files/electron-browser/remoteFileService.ts
浏览文件 @
0962b241
...
...
@@ -14,7 +14,7 @@ import { groupBy, isFalsyOrEmpty, distinct } from 'vs/base/common/arrays';
import
{
compare
}
from
'
vs/base/common/strings
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
{
Progress
}
from
'
vs/platform/progress/common/progress
'
;
import
{
decodeStream
,
encode
}
from
'
vs/base/node/encoding
'
;
import
{
decodeStream
,
encode
,
UTF8
,
UTF8_with_bom
}
from
'
vs/base/node/encoding
'
;
import
{
StringTrieMap
}
from
'
vs/base/common/map
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
...
...
@@ -24,6 +24,8 @@ import { IMessageService } from 'vs/platform/message/common/message';
import
{
IStorageService
}
from
'
vs/platform/storage/common/storage
'
;
import
{
ITextResourceConfigurationService
}
from
'
vs/editor/common/services/resourceConfiguration
'
;
import
{
IExtensionService
}
from
'
vs/platform/extensions/common/extensions
'
;
import
{
maxBufferLen
,
detectMimeAndEncodingFromBuffer
}
from
'
vs/base/node/mime
'
;
import
{
MIME_BINARY
}
from
'
vs/base/common/mime
'
;
function
toIFileStat
(
provider
:
IFileSystemProvider
,
tuple
:
[
URI
,
IStat
],
recurse
?:
(
tuple
:
[
URI
,
IStat
])
=>
boolean
):
TPromise
<
IFileStat
>
{
const
[
resource
,
stat
]
=
tuple
;
...
...
@@ -217,28 +219,73 @@ export class RemoteFileService extends FileService {
}
}
private
_doResolveContent
(
resource
:
URI
,
options
:
IResolveContentOptions
):
TPromise
<
IStreamContent
>
{
private
_doResolveContent
(
resource
:
URI
,
options
:
IResolveContentOptions
=
Object
.
create
(
null
)
):
TPromise
<
IStreamContent
>
{
return
this
.
_withProvider
(
resource
).
then
(
provider
=>
{
return
this
.
resolveFile
(
resource
).
then
(
fileStat
=>
{
const
guessEncoding
=
options
.
autoGuessEncoding
;
const
count
=
maxBufferLen
(
options
);
const
chunks
:
Buffer
[]
=
[];
return
provider
.
read
(
resource
,
0
,
count
,
new
Progress
<
Buffer
>
(
chunk
=>
chunks
.
push
(
chunk
))
).
then
(
bytesRead
=>
{
// send to bla
return
detectMimeAndEncodingFromBuffer
({
bytesRead
,
buffer
:
Buffer
.
concat
(
chunks
)
},
guessEncoding
);
}).
then
(
detected
=>
{
if
(
options
.
acceptTextOnly
&&
detected
.
mimes
.
indexOf
(
MIME_BINARY
)
>=
0
)
{
throw
new
Error
(
'
binary
'
);
}
const
encoding
=
this
.
getEncoding
(
resource
);
const
stream
=
decodeStream
(
encoding
);
let
preferredEncoding
:
string
;
if
(
options
&&
options
.
encoding
)
{
if
(
detected
.
encoding
===
UTF8
&&
options
.
encoding
===
UTF8
)
{
preferredEncoding
=
UTF8_with_bom
;
// indicate the file has BOM if we are to resolve with UTF 8
}
else
{
preferredEncoding
=
options
.
encoding
;
// give passed in encoding highest priority
}
}
else
if
(
detected
.
encoding
)
{
if
(
detected
.
encoding
===
UTF8
)
{
preferredEncoding
=
UTF8_with_bom
;
// if we detected UTF-8, it can only be because of a BOM
}
else
{
preferredEncoding
=
detected
.
encoding
;
}
// todo@remote - encoding logic should not be kept
// hostage inside the node file service
// } else if (super.configuredEncoding(resource) === UTF8_with_bom) {
}
else
{
preferredEncoding
=
UTF8
;
// if we did not detect UTF 8 BOM before, this can only be UTF 8 then
}
provider
.
read
(
resource
,
0
,
Number
.
MAX_VALUE
,
new
Progress
<
Buffer
>
(
chunk
=>
stream
.
write
(
chunk
))).
then
(()
=>
{
stream
.
end
();
},
err
=>
{
stream
.
emit
(
'
error
'
,
err
);
stream
.
end
();
});
// const encoding = this.getEncoding(resource);
const
stream
=
decodeStream
(
preferredEncoding
);
return
{
encoding
,
value
:
stream
,
resource
:
fileStat
.
resource
,
name
:
fileStat
.
name
,
etag
:
fileStat
.
etag
,
mtime
:
fileStat
.
mtime
,
};
// start with what we have already read
// and have a new stream to read the rest
let
offset
=
0
;
for
(
const
chunk
of
chunks
)
{
stream
.
write
(
chunk
);
offset
+=
chunk
.
length
;
}
provider
.
read
(
resource
,
offset
,
Number
.
MAX_VALUE
,
new
Progress
<
Buffer
>
(
chunk
=>
stream
.
write
(
chunk
))).
then
(()
=>
{
stream
.
end
();
},
err
=>
{
stream
.
emit
(
'
error
'
,
err
);
stream
.
end
();
});
return
{
encoding
:
preferredEncoding
,
value
:
stream
,
resource
:
fileStat
.
resource
,
name
:
fileStat
.
name
,
etag
:
fileStat
.
etag
,
mtime
:
fileStat
.
mtime
,
};
});
});
});
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录