@@ -14,6 +14,7 @@ import { multiaddr, type Multiaddr } from '@multiformats/multiaddr'
1414import { Signer } from 'ethers'
1515import { sleep } from '../../utils/General.js'
1616import { LoggerInstance } from '../../utils/Logger.js'
17+ import { concatUint8Arrays } from '../../utils/bytes.js'
1718import type { Connection , Stream } from '@libp2p/interface'
1819import {
1920 StorageObject ,
@@ -209,10 +210,10 @@ export class P2pProvider {
209210 }
210211 }
211212 if ( val ?. type === 'Buffer' && Array . isArray ( val . data ) ) {
212- return Buffer . from ( val . data ) . toString ( )
213+ return new TextDecoder ( ) . decode ( new Uint8Array ( val . data ) )
213214 }
214- if ( val instanceof Uint8Array || Buffer . isBuffer ( val ) ) {
215- return Buffer . from ( val ) . toString ( )
215+ if ( val instanceof Uint8Array ) {
216+ return new TextDecoder ( ) . decode ( val )
216217 }
217218 return val
218219 }
@@ -977,23 +978,23 @@ export class P2pProvider {
977978 }
978979
979980 // Collect binary file data. If the first frame wasn't a status JSON, it's data.
980- const chunks : Buffer [ ] = status === null ? [ Buffer . from ( firstBytes ) ] : [ ]
981+ const chunks : Uint8Array [ ] = status === null ? [ new Uint8Array ( firstBytes ) ] : [ ]
981982 try {
982983 while ( true ) {
983984 const chunk = await lp . read ( {
984985 signal : AbortSignal . timeout (
985986 this . p2pConfig . dialTimeout ?? DEFAULT_DIAL_TIMEOUT_MS
986987 )
987988 } )
988- chunks . push ( Buffer . from ( this . toUint8Array ( chunk ) ) )
989+ chunks . push ( new Uint8Array ( this . toUint8Array ( chunk ) ) )
989990 }
990991 } catch ( e ) {
991992 if ( ! ( e instanceof UnexpectedEOFError ) ) {
992993 throw e
993994 }
994995 }
995996
996- const combined = Buffer . concat ( chunks )
997+ const combined = concatUint8Arrays ( chunks )
997998 return {
998999 data : combined . buffer . slice (
9991000 combined . byteOffset ,
0 commit comments