Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
2d401764
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,发现更多精彩内容 >>
提交
2d401764
编写于
7月 11, 2019
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
files - add more tests for writing with stream
上级
0dcdc6a3
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
46 addition
and
24 deletion
+46
-24
src/vs/workbench/services/files/common/fileService.ts
src/vs/workbench/services/files/common/fileService.ts
+7
-1
src/vs/workbench/services/files/test/node/diskFileService.test.ts
...orkbench/services/files/test/node/diskFileService.test.ts
+39
-23
未找到文件。
src/vs/workbench/services/files/common/fileService.ts
浏览文件 @
2d401764
...
...
@@ -885,6 +885,8 @@ export class FileService extends Disposable implements IFileService {
let
posInFile
=
0
;
stream
.
on
(
'
data
'
,
async
chunk
=>
{
// pause stream to perform async write operation
stream
.
pause
();
try
{
...
...
@@ -895,7 +897,11 @@ export class FileService extends Disposable implements IFileService {
posInFile
+=
chunk
.
byteLength
;
stream
.
resume
();
// resume stream now that we have successfully written
// run this on the next tick to prevent increasing the
// execution stack because resume() may call the event
// handler again before finishing.
setTimeout
(()
=>
stream
.
resume
());
});
stream
.
on
(
'
error
'
,
error
=>
reject
(
error
));
...
...
src/vs/workbench/services/files/test/node/diskFileService.test.ts
浏览文件 @
2d401764
...
...
@@ -14,13 +14,13 @@ import { join, basename, dirname, posix } from 'vs/base/common/path';
import
{
getPathFromAmdModule
}
from
'
vs/base/common/amd
'
;
import
{
copy
,
rimraf
,
symlink
,
RimRafMode
,
rimrafSync
}
from
'
vs/base/node/pfs
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
existsSync
,
statSync
,
readdirSync
,
readFileSync
,
writeFileSync
,
renameSync
,
unlinkSync
,
mkdirSync
}
from
'
fs
'
;
import
{
existsSync
,
statSync
,
readdirSync
,
readFileSync
,
writeFileSync
,
renameSync
,
unlinkSync
,
mkdirSync
,
createReadStream
,
ReadStream
}
from
'
fs
'
;
import
{
FileOperation
,
FileOperationEvent
,
IFileStat
,
FileOperationResult
,
FileSystemProviderCapabilities
,
FileChangeType
,
IFileChange
,
FileChangesEvent
,
FileOperationError
,
etag
,
IStat
,
IFileStatWithMetadata
}
from
'
vs/platform/files/common/files
'
;
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
,
bufferTo
Stream
}
from
'
vs/base/common/buffer
'
;
import
{
VSBuffer
,
VSBufferReadable
,
writeableBufferStream
,
VSBufferReadable
Stream
}
from
'
vs/base/common/buffer
'
;
function
getByName
(
root
:
IFileStat
,
name
:
string
):
IFileStat
|
null
{
if
(
root
.
children
===
undefined
)
{
...
...
@@ -58,6 +58,16 @@ function toLineByLineReadable(content: string): VSBufferReadable {
};
}
function
nodeStreamToVSBufferStream
(
stream
:
ReadStream
):
VSBufferReadableStream
{
const
vsbufferStream
=
writeableBufferStream
();
stream
.
on
(
'
data
'
,
data
=>
vsbufferStream
.
write
(
VSBuffer
.
wrap
(
data
)));
stream
.
on
(
'
end
'
,
()
=>
vsbufferStream
.
end
());
stream
.
on
(
'
error
'
,
error
=>
vsbufferStream
.
error
(
error
));
return
vsbufferStream
;
}
export
class
TestDiskFileSystemProvider
extends
DiskFileSystemProvider
{
totalBytesRead
:
number
=
0
;
...
...
@@ -1545,46 +1555,52 @@ suite('Disk File Service', () => {
assert
.
equal
(
readFileSync
(
resource
.
fsPath
),
newContent
);
});
test
(
'
writeFile (
large file -
stream) - buffered
'
,
async
()
=>
{
test
(
'
writeFile (stream) - buffered
'
,
async
()
=>
{
setCapabilities
(
fileProvider
,
FileSystemProviderCapabilities
.
FileOpenReadWriteClose
);
const
resource
=
URI
.
file
(
join
(
testDir
,
'
lorem.txt
'
));
const
source
=
URI
.
file
(
join
(
testDir
,
'
small.txt
'
));
const
target
=
URI
.
file
(
join
(
testDir
,
'
small-copy.txt
'
));
const
content
=
readFileSync
(
resource
.
fsPath
);
const
newContent
=
content
.
toString
()
+
content
.
toString
(
);
const
fileStat
=
await
service
.
writeFile
(
target
,
nodeStreamToVSBufferStream
(
createReadStream
(
source
.
fsPath
))
);
assert
.
equal
(
fileStat
.
name
,
'
small-copy.txt
'
);
const
fileStat
=
await
service
.
writeFile
(
resource
,
bufferToStream
(
VSBuffer
.
fromString
(
newContent
)
));
assert
.
equal
(
fileStat
.
name
,
'
lorem.txt
'
);
assert
.
equal
(
readFileSync
(
source
.
fsPath
).
toString
(),
readFileSync
(
target
.
fsPath
).
toString
(
));
}
);
assert
.
equal
(
readFileSync
(
resource
.
fsPath
),
newContent
);
test
(
'
writeFile (large file - stream) - buffered
'
,
async
()
=>
{
setCapabilities
(
fileProvider
,
FileSystemProviderCapabilities
.
FileOpenReadWriteClose
);
const
source
=
URI
.
file
(
join
(
testDir
,
'
lorem.txt
'
));
const
target
=
URI
.
file
(
join
(
testDir
,
'
lorem-copy.txt
'
));
const
fileStat
=
await
service
.
writeFile
(
target
,
nodeStreamToVSBufferStream
(
createReadStream
(
source
.
fsPath
)));
assert
.
equal
(
fileStat
.
name
,
'
lorem-copy.txt
'
);
assert
.
equal
(
readFileSync
(
source
.
fsPath
).
toString
(),
readFileSync
(
target
.
fsPath
).
toString
());
});
test
(
'
writeFile (stream) - unbuffered
'
,
async
()
=>
{
setCapabilities
(
fileProvider
,
FileSystemProviderCapabilities
.
FileReadWrite
);
const
resource
=
URI
.
file
(
join
(
testDir
,
'
small.txt
'
));
const
source
=
URI
.
file
(
join
(
testDir
,
'
small.txt
'
));
const
target
=
URI
.
file
(
join
(
testDir
,
'
small-copy.txt
'
));
const
content
=
readFileSync
(
resource
.
fsPath
);
assert
.
equal
(
content
,
'
Small File
'
);
const
newContent
=
'
Updates to the small file
'
;
await
service
.
writeFile
(
resource
,
bufferToStream
(
VSBuffer
.
fromString
(
newContent
)));
const
fileStat
=
await
service
.
writeFile
(
target
,
nodeStreamToVSBufferStream
(
createReadStream
(
source
.
fsPath
)));
assert
.
equal
(
fileStat
.
name
,
'
small-copy.txt
'
);
assert
.
equal
(
readFileSync
(
resource
.
fsPath
),
newContent
);
assert
.
equal
(
readFileSync
(
source
.
fsPath
).
toString
(),
readFileSync
(
target
.
fsPath
).
toString
()
);
});
test
(
'
writeFile (large file - stream) - unbuffered
'
,
async
()
=>
{
setCapabilities
(
fileProvider
,
FileSystemProviderCapabilities
.
FileReadWrite
);
const
resource
=
URI
.
file
(
join
(
testDir
,
'
lorem.txt
'
));
const
source
=
URI
.
file
(
join
(
testDir
,
'
lorem.txt
'
));
const
target
=
URI
.
file
(
join
(
testDir
,
'
lorem-copy.txt
'
));
const
content
=
readFileSync
(
resource
.
fsPath
);
const
newContent
=
content
.
toString
()
+
content
.
toString
(
);
const
fileStat
=
await
service
.
writeFile
(
target
,
nodeStreamToVSBufferStream
(
createReadStream
(
source
.
fsPath
))
);
assert
.
equal
(
fileStat
.
name
,
'
lorem-copy.txt
'
);
const
fileStat
=
await
service
.
writeFile
(
resource
,
bufferToStream
(
VSBuffer
.
fromString
(
newContent
)));
assert
.
equal
(
fileStat
.
name
,
'
lorem.txt
'
);
assert
.
equal
(
readFileSync
(
resource
.
fsPath
),
newContent
);
assert
.
equal
(
readFileSync
(
source
.
fsPath
).
toString
(),
readFileSync
(
target
.
fsPath
).
toString
());
});
test
(
'
writeFile (file is created including parents)
'
,
async
()
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录