Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
4a9223c0
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4a9223c0
编写于
7月 11, 2019
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
files - properly add stream support to create/write
上级
2d401764
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
7 deletion
+19
-7
src/vs/platform/files/common/files.ts
src/vs/platform/files/common/files.ts
+2
-2
src/vs/workbench/services/files/common/fileService.ts
src/vs/workbench/services/files/common/fileService.ts
+2
-2
src/vs/workbench/services/files/test/node/diskFileService.test.ts
...orkbench/services/files/test/node/diskFileService.test.ts
+15
-3
未找到文件。
src/vs/platform/files/common/files.ts
浏览文件 @
4a9223c0
...
...
@@ -105,7 +105,7 @@ export interface IFileService {
/**
* Updates the content replacing its previous value.
*/
writeFile
(
resource
:
URI
,
bufferOrReadable
:
VSBuffer
|
VSBufferReadable
,
options
?:
IWriteFileOptions
):
Promise
<
IFileStatWithMetadata
>
;
writeFile
(
resource
:
URI
,
bufferOrReadable
OrStream
:
VSBuffer
|
VSBufferReadable
|
VSBufferReadableStream
,
options
?:
IWriteFileOptions
):
Promise
<
IFileStatWithMetadata
>
;
/**
* Moves the file/folder to a new path identified by the resource.
...
...
@@ -127,7 +127,7 @@ export interface IFileService {
*
* The optional parameter content can be used as value to fill into the new file.
*/
createFile
(
resource
:
URI
,
bufferOrReadable
?:
VSBuffer
|
VSBufferReadable
,
options
?:
ICreateFileOptions
):
Promise
<
IFileStatWithMetadata
>
;
createFile
(
resource
:
URI
,
bufferOrReadable
OrStream
?:
VSBuffer
|
VSBufferReadable
|
VSBufferReadableStream
,
options
?:
ICreateFileOptions
):
Promise
<
IFileStatWithMetadata
>
;
/**
* Creates a new folder with the given path. The returned promise
...
...
src/vs/workbench/services/files/common/fileService.ts
浏览文件 @
4a9223c0
...
...
@@ -264,7 +264,7 @@ export class FileService extends Disposable implements IFileService {
//#region File Reading/Writing
async
createFile
(
resource
:
URI
,
bufferOrReadable
:
VSBuffer
|
VSBufferReadable
=
VSBuffer
.
fromString
(
''
),
options
?:
ICreateFileOptions
):
Promise
<
IFileStatWithMetadata
>
{
async
createFile
(
resource
:
URI
,
bufferOrReadable
OrStream
:
VSBuffer
|
VSBufferReadable
|
VSBufferReadableStream
=
VSBuffer
.
fromString
(
''
),
options
?:
ICreateFileOptions
):
Promise
<
IFileStatWithMetadata
>
{
// validate overwrite
const
overwrite
=
!!
(
options
&&
options
.
overwrite
);
...
...
@@ -273,7 +273,7 @@ export class FileService extends Disposable implements IFileService {
}
// do write into file (this will create it too)
const
fileStat
=
await
this
.
writeFile
(
resource
,
bufferOrReadable
);
const
fileStat
=
await
this
.
writeFile
(
resource
,
bufferOrReadable
OrStream
);
// events
this
.
_onAfterOperation
.
fire
(
new
FileOperationEvent
(
resource
,
FileOperation
.
CREATE
,
fileStat
));
...
...
src/vs/workbench/services/files/test/node/diskFileService.test.ts
浏览文件 @
4a9223c0
...
...
@@ -20,7 +20,7 @@ import { NullLogService } from 'vs/platform/log/common/log';
import
{
isLinux
,
isWindows
}
from
'
vs/base/common/platform
'
;
import
{
DisposableStore
}
from
'
vs/base/common/lifecycle
'
;
import
{
isEqual
}
from
'
vs/base/common/resources
'
;
import
{
VSBuffer
,
VSBufferReadable
,
writeableBufferStream
,
VSBufferReadableStream
}
from
'
vs/base/common/buffer
'
;
import
{
VSBuffer
,
VSBufferReadable
,
writeableBufferStream
,
VSBufferReadableStream
,
bufferToReadable
,
bufferToStream
}
from
'
vs/base/common/buffer
'
;
function
getByName
(
root
:
IFileStat
,
name
:
string
):
IFileStat
|
null
{
if
(
root
.
children
===
undefined
)
{
...
...
@@ -1336,12 +1336,24 @@ suite('Disk File Service', () => {
});
test
(
'
createFile
'
,
async
()
=>
{
assertCreateFile
(
contents
=>
VSBuffer
.
fromString
(
contents
));
});
test
(
'
createFile (readable)
'
,
async
()
=>
{
assertCreateFile
(
contents
=>
bufferToReadable
(
VSBuffer
.
fromString
(
contents
)));
});
test
(
'
createFile (stream)
'
,
async
()
=>
{
assertCreateFile
(
contents
=>
bufferToStream
(
VSBuffer
.
fromString
(
contents
)));
});
async
function
assertCreateFile
(
converter
:
(
content
:
string
)
=>
VSBuffer
|
VSBufferReadable
|
VSBufferReadableStream
):
Promise
<
void
>
{
let
event
:
FileOperationEvent
;
disposables
.
add
(
service
.
onAfterOperation
(
e
=>
event
=
e
));
const
contents
=
'
Hello World
'
;
const
resource
=
URI
.
file
(
join
(
testDir
,
'
test.txt
'
));
const
fileStat
=
await
service
.
createFile
(
resource
,
VSBuffer
.
fromString
(
contents
));
const
fileStat
=
await
service
.
createFile
(
resource
,
converter
(
contents
));
assert
.
equal
(
fileStat
.
name
,
'
test.txt
'
);
assert
.
equal
(
existsSync
(
fileStat
.
resource
.
fsPath
),
true
);
assert
.
equal
(
readFileSync
(
fileStat
.
resource
.
fsPath
),
contents
);
...
...
@@ -1350,7 +1362,7 @@ suite('Disk File Service', () => {
assert
.
equal
(
event
!
.
resource
.
fsPath
,
resource
.
fsPath
);
assert
.
equal
(
event
!
.
operation
,
FileOperation
.
CREATE
);
assert
.
equal
(
event
!
.
target
!
.
resource
.
fsPath
,
resource
.
fsPath
);
}
);
}
test
(
'
createFile (does not overwrite by default)
'
,
async
()
=>
{
const
contents
=
'
Hello World
'
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录