@libp2p/utils 6.7.2-da78fa851 → 6.7.2-e8398d97e
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.
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +0 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/queue/index.d.ts +0 -6
- package/dist/src/queue/index.d.ts.map +1 -1
- package/dist/src/queue/index.js.map +1 -1
- package/package.json +7 -10
- package/src/index.ts +0 -2
- package/src/queue/index.ts +0 -7
- package/dist/src/merge-options.d.ts +0 -7
- package/dist/src/merge-options.d.ts.map +0 -1
- package/dist/src/merge-options.js +0 -128
- package/dist/src/merge-options.js.map +0 -1
- package/dist/src/socket-writer.browser.d.ts +0 -2
- package/dist/src/socket-writer.browser.d.ts.map +0 -1
- package/dist/src/socket-writer.browser.js +0 -4
- package/dist/src/socket-writer.browser.js.map +0 -1
- package/dist/src/socket-writer.d.ts +0 -19
- package/dist/src/socket-writer.d.ts.map +0 -1
- package/dist/src/socket-writer.js +0 -43
- package/dist/src/socket-writer.js.map +0 -1
- package/src/merge-options.ts +0 -161
- package/src/socket-writer.browser.ts +0 -3
- package/src/socket-writer.ts +0 -64
package/src/socket-writer.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import stream from 'node:stream'
|
|
2
|
-
import { Uint8ArrayList } from 'uint8arraylist'
|
|
3
|
-
|
|
4
|
-
export interface SocketWriter {
|
|
5
|
-
/**
|
|
6
|
-
* Write any available data into the socket, if the socket's internal write
|
|
7
|
-
* buffer has available capacity
|
|
8
|
-
*/
|
|
9
|
-
pull (): boolean
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Write data into the socket, returns false if the socket's internal write
|
|
13
|
-
* buffer is at capacity
|
|
14
|
-
*/
|
|
15
|
-
write (data: Uint8Array | Uint8Array[] | Uint8ArrayList): boolean
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated delete if unused
|
|
20
|
-
*/
|
|
21
|
-
export function socketWriter (socket: stream.Duplex): SocketWriter {
|
|
22
|
-
const queue = new Uint8ArrayList()
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
pull (): boolean {
|
|
26
|
-
if (socket.writableNeedDrain) {
|
|
27
|
-
return false
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
for (const buf of queue) {
|
|
31
|
-
queue.consume(buf.byteLength)
|
|
32
|
-
|
|
33
|
-
if (!socket.write(buf)) {
|
|
34
|
-
// continue writing after drain event. this is a synchronous operation
|
|
35
|
-
// so it will not interleave with the `this.writeToSocket()`
|
|
36
|
-
// invocation in this.sendData so all data will be sent in-order
|
|
37
|
-
if (queue.byteLength > 0) {
|
|
38
|
-
socket.once('drain', () => {
|
|
39
|
-
this.pull()
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return false
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return true
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
write (data: Uint8Array | Uint8Array[] | Uint8ArrayList): boolean {
|
|
51
|
-
if (Array.isArray(data)) {
|
|
52
|
-
queue.appendAll(data)
|
|
53
|
-
} else {
|
|
54
|
-
queue.append(data)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (socket.writableNeedDrain) {
|
|
58
|
-
return false
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return this.pull()
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|