@libp2p/daemon-protocol 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@ import { handshake } from 'it-handshake'
3
3
  import { logger } from '@libp2p/logger'
4
4
  import type { Duplex, Source } from 'it-stream-types'
5
5
  import type { Handshake } from 'it-handshake'
6
+ import type { Uint8ArrayList } from 'uint8arraylist'
6
7
 
7
8
  const log = logger('libp2p:daemon-protocol:stream-handler')
8
9
 
@@ -13,8 +14,8 @@ export interface StreamHandlerOptions {
13
14
 
14
15
  export class StreamHandler {
15
16
  private readonly stream: Duplex<Uint8Array>
16
- private readonly shake: Handshake
17
- public decoder: Source<Uint8Array>
17
+ private readonly shake: Handshake<Uint8Array>
18
+ public decoder: Source<Uint8ArrayList>
18
19
  /**
19
20
  * Create a stream handler for connection
20
21
  */
@@ -33,7 +34,7 @@ export class StreamHandler {
33
34
  // @ts-expect-error decoder is really a generator
34
35
  const msg = await this.decoder.next()
35
36
  if (msg.value != null) {
36
- return msg.value.slice()
37
+ return msg.value.subarray()
37
38
  }
38
39
 
39
40
  log('read received no value, closing stream')
@@ -41,10 +42,10 @@ export class StreamHandler {
41
42
  await this.close()
42
43
  }
43
44
 
44
- write (msg: Uint8Array) {
45
+ write (msg: Uint8Array | Uint8ArrayList) {
45
46
  log('write message')
46
47
  this.shake.write(
47
- lp.encode.single(msg).slice()
48
+ lp.encode.single(msg).subarray()
48
49
  )
49
50
  }
50
51