Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: read stream data using lp stream #242

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions packages/libp2p-daemon-protocol/src/stream-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,12 @@ export class StreamHandler {
/**
* Read and decode message
*/
async read (): Promise<Uint8Array | undefined> {
// @ts-expect-error decoder is really a generator
const msg = await this.decoder.next()
if (msg.value != null) {
return msg.value.subarray()
async read (): Promise<Uint8ArrayList | undefined> {
try {
return await this.lp.read()
} catch (err) {
log.error('read received no value', err)
}

log('read received no value, closing stream')
// End the stream, we didn't get data
await this.close()
}

async write (msg: Uint8Array | Uint8ArrayList): Promise<void> {
Expand Down