MCPcopy
hub / github.com/vuejs/core / pipeToWebWritable

Function pipeToWebWritable

packages/server-renderer/src/renderToStream.ts:182–214  ·  view source on GitHub ↗
(
  input: App | VNode,
  context: SSRContext | undefined = {},
  writable: WritableStream,
)

Source from the content-addressed store, hash-verified

180}
181
182export function pipeToWebWritable(
183 input: App | VNode,
184 context: SSRContext | undefined = {},
185 writable: WritableStream,
186): void {
187 const writer = writable.getWriter()
188 const encoder = new TextEncoder()
189
190 // #4287 CloudFlare workers do not implement `ready` property
191 let hasReady = false
192 try {
193 hasReady = isPromise(writer.ready)
194 } catch (e: any) {}
195
196 renderToSimpleStream(input, context, {
197 async push(content) {
198 if (hasReady) {
199 await writer.ready
200 }
201 if (content != null) {
202 return writer.write(encoder.encode(content))
203 } else {
204 return writer.close()
205 }
206 },
207 destroy(err) {
208 // TODO better error handling?
209 // eslint-disable-next-line no-console
210 console.log(err)
211 writer.close()
212 },
213 })
214}

Callers 1

webStream.spec.tsFile · 0.90

Calls 2

isPromiseFunction · 0.90
renderToSimpleStreamFunction · 0.85

Tested by

no test coverage detected