@nxtedition/shared 1.0.1 → 1.1.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.
- package/index.js +18 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -67,9 +67,20 @@ export function writer({ sharedState, sharedBuffer }) {
|
|
|
67
67
|
let flushing = null
|
|
68
68
|
|
|
69
69
|
function tryWrite(...raw) {
|
|
70
|
+
if (Array.isArray(raw[0])) {
|
|
71
|
+
raw = raw[0]
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!raw.length) {
|
|
75
|
+
return true
|
|
76
|
+
}
|
|
77
|
+
|
|
70
78
|
readPos = Atomics.load(state, READ_INDEX)
|
|
71
79
|
|
|
72
|
-
|
|
80
|
+
let len = 0
|
|
81
|
+
for (const buf of raw) {
|
|
82
|
+
len += buf.byteLength ?? Buffer.byteLength(buf)
|
|
83
|
+
}
|
|
73
84
|
|
|
74
85
|
if (size - writePos < len + 4) {
|
|
75
86
|
if (readPos < len + 4) {
|
|
@@ -90,8 +101,12 @@ export function writer({ sharedState, sharedBuffer }) {
|
|
|
90
101
|
writePos += 4
|
|
91
102
|
|
|
92
103
|
for (const buf of raw) {
|
|
93
|
-
|
|
94
|
-
|
|
104
|
+
if (typeof buf === 'string') {
|
|
105
|
+
writePos += buffer.write(buf, writePos)
|
|
106
|
+
} else {
|
|
107
|
+
buffer.set(buf, writePos)
|
|
108
|
+
writePos += buf.byteLength
|
|
109
|
+
}
|
|
95
110
|
}
|
|
96
111
|
|
|
97
112
|
Atomics.store(state, WRITE_INDEX, writePos)
|