Skip to content

Commit

Permalink
fix: read stream data using lp stream (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain authored Nov 30, 2023
1 parent ed64183 commit ee746f6
Showing 1 changed file with 5 additions and 9 deletions.
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

0 comments on commit ee746f6

Please sign in to comment.