This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1a68a2
commit 134c633
Showing
4 changed files
with
48 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import defer from 'p-defer' | ||
import map from 'it-map' | ||
import type { Source, Duplex } from 'it-stream-types' | ||
import { Uint8ArrayList } from 'uint8arraylist' | ||
|
||
/** | ||
* A pair of streams where one drains from the other | ||
*/ | ||
export function pair (): Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array> { | ||
const deferred = defer<Source<Uint8ArrayList | Uint8Array>>() | ||
let piped = false | ||
|
||
return { | ||
sink: async source => { | ||
if (piped) { | ||
throw new Error('already piped') | ||
} | ||
|
||
piped = true | ||
deferred.resolve(source) | ||
}, | ||
source: (async function * () { | ||
const source = await deferred.promise | ||
|
||
yield * map(source, (buf) => buf instanceof Uint8Array ? new Uint8ArrayList(buf) : buf) | ||
}()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters