Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
mat-cacher
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
mat-cacher
Commits
cb150597
Commit
cb150597
authored
Jun 15, 2025
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first
parents
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
+53
-0
src/utility/tee-stream.ts
src/utility/tee-stream.ts
+53
-0
No files found.
src/utility/tee-stream.ts
0 → 100644
View file @
cb150597
import
{
Readable
}
from
'
stream
'
;
export
function
teex
<
T
=
any
>
(
source
:
Readable
,
forks
:
number
=
2
):
Readable
[]
{
const
streams
=
new
Array
<
Readable
>
(
forks
);
const
status
=
new
Array
<
boolean
>
(
forks
).
fill
(
true
);
let
ended
=
false
;
for
(
let
i
=
0
;
i
<
forks
;
i
++
)
{
streams
[
i
]
=
new
Readable
({
read
(
size
)
{
const
shouldResume
=
!
status
[
i
];
status
[
i
]
=
true
;
if
(
shouldResume
&&
allReadable
())
source
.
resume
();
},
});
}
source
.
on
(
'
end
'
,
()
=>
{
ended
=
true
;
for
(
const
stream
of
streams
)
{
stream
.
push
(
null
);
}
});
source
.
on
(
'
error
'
,
(
err
:
Error
)
=>
{
for
(
const
stream
of
streams
)
{
stream
.
destroy
(
err
);
}
});
source
.
on
(
'
close
'
,
()
=>
{
if
(
ended
)
return
;
for
(
const
stream
of
streams
)
{
stream
.
destroy
();
}
});
source
.
on
(
'
data
'
,
(
data
:
T
)
=>
{
let
needsPause
=
false
;
for
(
let
i
=
0
;
i
<
streams
.
length
;
i
++
)
{
status
[
i
]
=
streams
[
i
].
push
(
data
);
if
(
!
status
[
i
])
needsPause
=
true
;
}
if
(
needsPause
)
source
.
pause
();
});
return
streams
;
function
allReadable
():
boolean
{
return
status
.
every
(
Boolean
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment