MCPcopy Index your code
hub / github.com/coder/mux / pipeReadableToWebWritable

Function pipeReadableToWebWritable

src/node/runtime/SSHRuntime.ts:235–267  ·  view source on GitHub ↗
(
  readable: NodeJS.ReadableStream | null | undefined,
  writable: WritableStream<Uint8Array>,
  abortSignal?: AbortSignal
)

Source from the content-addressed store, hash-verified

233}
234
235async function pipeReadableToWebWritable(
236 readable: NodeJS.ReadableStream | null | undefined,
237 writable: WritableStream<Uint8Array>,
238 abortSignal?: AbortSignal
239): Promise<void> {
240 if (!readable) {
241 throw new Error("Missing git bundle output stream");
242 }
243
244 const writer = writable.getWriter();
245 try {
246 for await (const chunk of readable) {
247 if (abortSignal?.aborted) {
248 throw new Error("Bundle creation aborted");
249 }
250 const data =
251 typeof chunk === "string"
252 ? Buffer.from(chunk)
253 : chunk instanceof Uint8Array
254 ? chunk
255 : Buffer.from(chunk);
256 await writer.write(data);
257 }
258 await writer.close();
259 } catch (error) {
260 try {
261 await writer.abort(error);
262 } catch {
263 writer.releaseLock();
264 }
265 throw error;
266 }
267}
268
269function createAbortController(
270 timeoutMs: number | undefined,

Calls 3

writeMethod · 0.65
closeMethod · 0.65
abortMethod · 0.65

Tested by

no test coverage detected