Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
deps: update all it-* deps to the latest versions (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain authored Apr 3, 2023
1 parent f51c2bf commit cf9133a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@
"@libp2p/interfaces": "^3.2.0",
"@libp2p/logger": "^2.0.0",
"abortable-iterator": "^4.0.2",
"it-first": "^2.0.0",
"it-first": "^3.0.1",
"it-handshake": "^4.1.2",
"it-length-prefixed": "^8.0.3",
"it-length-prefixed": "^9.0.0",
"it-merge": "^3.0.0",
"it-pipe": "^2.0.4",
"it-pipe": "^3.0.0",
"it-pushable": "^3.1.0",
"it-reader": "^6.0.1",
"it-stream-types": "^1.0.4",
Expand All @@ -160,10 +160,10 @@
},
"devDependencies": {
"@types/varint": "^6.0.0",
"aegir": "^37.2.0",
"aegir": "^38.1.8",
"iso-random-stream": "^2.0.2",
"it-all": "^3.0.1",
"it-map": "^2.0.0",
"it-map": "^3.0.2",
"it-pair": "^2.0.3",
"p-timeout": "^6.0.0",
"timeout-abort-controller": "^3.0.0",
Expand Down
10 changes: 5 additions & 5 deletions src/multistream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function encode (buffer: Uint8Array | Uint8ArrayList): Uint8ArrayList {
/**
* `write` encodes and writes a single buffer
*/
export function write (writer: Pushable<any>, buffer: Uint8Array | Uint8ArrayList, options: MultistreamSelectInit = {}) {
export function write (writer: Pushable<any>, buffer: Uint8Array | Uint8ArrayList, options: MultistreamSelectInit = {}): void {
const encoded = encode(buffer)

if (options.writeBytes === true) {
Expand All @@ -41,7 +41,7 @@ export function write (writer: Pushable<any>, buffer: Uint8Array | Uint8ArrayLis
/**
* `writeAll` behaves like `write`, except it encodes an array of items as a single write
*/
export function writeAll (writer: Pushable<any>, buffers: Uint8Array[], options: MultistreamSelectInit = {}) {
export function writeAll (writer: Pushable<any>, buffers: Uint8Array[], options: MultistreamSelectInit = {}): void {
const list = new Uint8ArrayList()

for (const buf of buffers) {
Expand Down Expand Up @@ -71,13 +71,13 @@ export async function read (reader: Reader, options?: AbortOptions): Promise<Uin
}

// Once the length has been parsed, read chunk for that length
const onLength = (l: number) => {
const onLength = (l: number): void => {
byteLength = l
}

const buf = await pipe(
input,
lp.decode({ onLength, maxDataLength: MAX_PROTOCOL_LENGTH }),
(source) => lp.decode(source, { onLength, maxDataLength: MAX_PROTOCOL_LENGTH }),
async (source) => await first(source)
)

Expand All @@ -93,7 +93,7 @@ export async function read (reader: Reader, options?: AbortOptions): Promise<Uin
return buf.sublist(0, -1) // Remove newline
}

export async function readString (reader: Reader, options?: AbortOptions) {
export async function readString (reader: Reader, options?: AbortOptions): Promise<string> {
const buf = await read(reader, options)

return uint8ArrayToString(buf.subarray())
Expand Down
34 changes: 18 additions & 16 deletions src/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,25 @@ export function lazySelect (stream: Duplex<any>, protocol: string): ProtocolStre
let negotiated = false
return {
stream: {
sink: async source => await stream.sink((async function * () {
let first = true
for await (const chunk of merge(source, negotiateTrigger)) {
if (first) {
first = false
negotiated = true
negotiateTrigger.end()
const p1 = uint8ArrayFromString(PROTOCOL_ID)
const p2 = uint8ArrayFromString(protocol)
const list = new Uint8ArrayList(multistream.encode(p1), multistream.encode(p2))
if (chunk.length > 0) list.append(chunk)
yield * list
} else {
yield chunk
sink: async source => {
await stream.sink((async function * () {
let first = true
for await (const chunk of merge(source, negotiateTrigger)) {
if (first) {
first = false
negotiated = true
negotiateTrigger.end()
const p1 = uint8ArrayFromString(PROTOCOL_ID)
const p2 = uint8ArrayFromString(protocol)
const list = new Uint8ArrayList(multistream.encode(p1), multistream.encode(p2))
if (chunk.length > 0) list.append(chunk)
yield * list
} else {
yield chunk
}
}
}
})()),
})())
},
source: (async function * () {
if (!negotiated) negotiateTrigger.push(new Uint8Array())
const byteReader = reader(stream.source)
Expand Down
2 changes: 1 addition & 1 deletion test/listener.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('Listener', () => {
// Decode each of the protocols from the reader
const lsProtocols = await pipe(
protocolsReader,
Lp.decode(),
(source) => Lp.decode(source),
// Stringify and remove the newline
(source) => map(source, (buf) => uint8ArrayToString(buf.subarray()).trim()),
async (source) => await all(source)
Expand Down

0 comments on commit cf9133a

Please sign in to comment.