Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
0048ef82
V
Vscode
项目概览
徽霖
/
Vscode
通知
9
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,发现更多精彩内容 >>
提交
0048ef82
编写于
7月 11, 2019
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
files - introduce generic stream interface and offer utility to convert to vsbuffer stream
上级
8b497a90
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
23 deletion
+26
-23
src/vs/base/common/buffer.ts
src/vs/base/common/buffer.ts
+20
-7
src/vs/workbench/services/files/test/node/diskFileService.test.ts
...orkbench/services/files/test/node/diskFileService.test.ts
+6
-16
未找到文件。
src/vs/base/common/buffer.ts
浏览文件 @
0048ef82
...
...
@@ -141,18 +141,13 @@ export interface VSBufferReadable {
read
():
VSBuffer
|
null
;
}
/**
* A buffer readable stream emits data to listeners. The stream
* will only start emitting when the first data listener has
* been added or the resume() method has been called.
*/
export
interface
VSBufferReadableStream
{
export
interface
ReadableStream
<
T
>
{
/**
* The 'data' event is emitted whenever the stream is
* relinquishing ownership of a chunk of data to a consumer.
*/
on
(
event
:
'
data
'
,
callback
:
(
chunk
:
VSBuffer
)
=>
void
):
void
;
on
(
event
:
'
data
'
,
callback
:
(
chunk
:
T
)
=>
void
):
void
;
/**
* Emitted when any error occurs.
...
...
@@ -182,6 +177,11 @@ export interface VSBufferReadableStream {
destroy
():
void
;
}
/**
* A readable stream that sends data via VSBuffer.
*/
export
interface
VSBufferReadableStream
extends
ReadableStream
<
VSBuffer
>
{
}
export
function
isVSBufferReadableStream
(
obj
:
any
):
obj
is
VSBufferReadableStream
{
const
candidate
:
VSBufferReadableStream
=
obj
;
...
...
@@ -245,6 +245,19 @@ export function bufferToStream(buffer: VSBuffer): VSBufferReadableStream {
return
stream
;
}
/**
* Helper to create a VSBufferStream from a Uint8Array stream.
*/
export
function
toVSBufferReadableStream
(
stream
:
ReadableStream
<
Uint8Array
>
):
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
;
}
/**
* Helper to create a VSBufferStream that can be pushed
* buffers to. Will only start to emit data when a listener
...
...
src/vs/workbench/services/files/test/node/diskFileService.test.ts
浏览文件 @
0048ef82
...
...
@@ -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
,
createReadStream
,
ReadStream
}
from
'
fs
'
;
import
{
existsSync
,
statSync
,
readdirSync
,
readFileSync
,
writeFileSync
,
renameSync
,
unlinkSync
,
mkdirSync
,
createReadStream
}
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
,
writeableBuffer
Stream
,
VSBufferReadableStream
,
bufferToReadable
,
bufferToStream
}
from
'
vs/base/common/buffer
'
;
import
{
VSBuffer
,
VSBufferReadable
,
toVSBufferReadable
Stream
,
VSBufferReadableStream
,
bufferToReadable
,
bufferToStream
}
from
'
vs/base/common/buffer
'
;
function
getByName
(
root
:
IFileStat
,
name
:
string
):
IFileStat
|
null
{
if
(
root
.
children
===
undefined
)
{
...
...
@@ -58,16 +58,6 @@ 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
;
...
...
@@ -1573,7 +1563,7 @@ suite('Disk File Service', () => {
const
source
=
URI
.
file
(
join
(
testDir
,
'
small.txt
'
));
const
target
=
URI
.
file
(
join
(
testDir
,
'
small-copy.txt
'
));
const
fileStat
=
await
service
.
writeFile
(
target
,
nodeStreamToVSBuffer
Stream
(
createReadStream
(
source
.
fsPath
)));
const
fileStat
=
await
service
.
writeFile
(
target
,
toVSBufferReadable
Stream
(
createReadStream
(
source
.
fsPath
)));
assert
.
equal
(
fileStat
.
name
,
'
small-copy.txt
'
);
assert
.
equal
(
readFileSync
(
source
.
fsPath
).
toString
(),
readFileSync
(
target
.
fsPath
).
toString
());
...
...
@@ -1585,7 +1575,7 @@ suite('Disk File Service', () => {
const
source
=
URI
.
file
(
join
(
testDir
,
'
lorem.txt
'
));
const
target
=
URI
.
file
(
join
(
testDir
,
'
lorem-copy.txt
'
));
const
fileStat
=
await
service
.
writeFile
(
target
,
nodeStreamToVSBuffer
Stream
(
createReadStream
(
source
.
fsPath
)));
const
fileStat
=
await
service
.
writeFile
(
target
,
toVSBufferReadable
Stream
(
createReadStream
(
source
.
fsPath
)));
assert
.
equal
(
fileStat
.
name
,
'
lorem-copy.txt
'
);
assert
.
equal
(
readFileSync
(
source
.
fsPath
).
toString
(),
readFileSync
(
target
.
fsPath
).
toString
());
...
...
@@ -1597,7 +1587,7 @@ suite('Disk File Service', () => {
const
source
=
URI
.
file
(
join
(
testDir
,
'
small.txt
'
));
const
target
=
URI
.
file
(
join
(
testDir
,
'
small-copy.txt
'
));
const
fileStat
=
await
service
.
writeFile
(
target
,
nodeStreamToVSBuffer
Stream
(
createReadStream
(
source
.
fsPath
)));
const
fileStat
=
await
service
.
writeFile
(
target
,
toVSBufferReadable
Stream
(
createReadStream
(
source
.
fsPath
)));
assert
.
equal
(
fileStat
.
name
,
'
small-copy.txt
'
);
assert
.
equal
(
readFileSync
(
source
.
fsPath
).
toString
(),
readFileSync
(
target
.
fsPath
).
toString
());
...
...
@@ -1609,7 +1599,7 @@ suite('Disk File Service', () => {
const
source
=
URI
.
file
(
join
(
testDir
,
'
lorem.txt
'
));
const
target
=
URI
.
file
(
join
(
testDir
,
'
lorem-copy.txt
'
));
const
fileStat
=
await
service
.
writeFile
(
target
,
nodeStreamToVSBuffer
Stream
(
createReadStream
(
source
.
fsPath
)));
const
fileStat
=
await
service
.
writeFile
(
target
,
toVSBufferReadable
Stream
(
createReadStream
(
source
.
fsPath
)));
assert
.
equal
(
fileStat
.
name
,
'
lorem-copy.txt
'
);
assert
.
equal
(
readFileSync
(
source
.
fsPath
).
toString
(),
readFileSync
(
target
.
fsPath
).
toString
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录