@srfnstack/spliffy 1.2.6 → 1.2.7
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/package.json +1 -1
- package/src/decorator.mjs +30 -26
package/package.json
CHANGED
package/src/decorator.mjs
CHANGED
|
@@ -125,29 +125,31 @@ export function decorateResponse (res, req, finalizeResponse, errorTransformer,
|
|
|
125
125
|
|
|
126
126
|
res.uwsWrite = res.write
|
|
127
127
|
res.write = (chunk, encoding, cb) => {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
cb
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
cb
|
|
147
|
-
|
|
148
|
-
|
|
128
|
+
res.cork(() => {
|
|
129
|
+
try {
|
|
130
|
+
res.streaming = true
|
|
131
|
+
res.flushHeaders()
|
|
132
|
+
let data
|
|
133
|
+
if (chunk instanceof Buffer) {
|
|
134
|
+
data = toArrayBuffer(chunk)
|
|
135
|
+
} else if (typeof chunk === 'string') {
|
|
136
|
+
data = toArrayBuffer(Buffer.from(chunk, encoding || 'utf8'))
|
|
137
|
+
} else {
|
|
138
|
+
data = toArrayBuffer(Buffer.from(JSON.stringify(chunk), encoding || 'utf8'))
|
|
139
|
+
}
|
|
140
|
+
const result = res.uwsWrite(data)
|
|
141
|
+
if (typeof cb === 'function') {
|
|
142
|
+
cb()
|
|
143
|
+
}
|
|
144
|
+
return result
|
|
145
|
+
} catch (e) {
|
|
146
|
+
if (typeof cb === 'function') {
|
|
147
|
+
cb(e)
|
|
148
|
+
} else {
|
|
149
|
+
throw e
|
|
150
|
+
}
|
|
149
151
|
}
|
|
150
|
-
}
|
|
152
|
+
})
|
|
151
153
|
}
|
|
152
154
|
let outStream
|
|
153
155
|
res.getWritable = () => {
|
|
@@ -177,10 +179,12 @@ export function decorateResponse (res, req, finalizeResponse, errorTransformer,
|
|
|
177
179
|
}
|
|
178
180
|
// provide writableEnded like node does, with slightly different behavior
|
|
179
181
|
if (!res.writableEnded) {
|
|
180
|
-
res.
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
res.cork(() => {
|
|
183
|
+
res.flushHeaders()
|
|
184
|
+
uwsEnd.call(res, body)
|
|
185
|
+
res.writableEnded = true
|
|
186
|
+
res.ended = true
|
|
187
|
+
})
|
|
184
188
|
}
|
|
185
189
|
if (typeof res.onEnd === 'function') {
|
|
186
190
|
res.onEnd()
|