MCPcopy Index your code
hub / github.com/Effect-TS/effect / persisted

Function persisted

packages/platform-bun/src/internal/multipart.ts:30–52  ·  view source on GitHub ↗
(source: Request)

Source from the content-addressed store, hash-verified

28
29/** @internal */
30export const persisted = (source: Request) =>
31 Multipart.toPersisted(stream(source), (path, file) =>
32 Effect.tryPromise({
33 try: async () => {
34 const fileImpl = file as FileImpl
35 const writer = Bun.file(path).writer()
36 const reader = fileImpl.file.readable.getReader()
37 try {
38 while (true) {
39 const { done, value } = await reader.readMany()
40 if (done) break
41 for (const chunk of value) {
42 writer.write(chunk)
43 }
44 await writer.flush()
45 }
46 } finally {
47 reader.cancel()
48 await writer.end()
49 }
50 },
51 catch: (cause) => new Multipart.MultipartError({ reason: "InternalError", cause })
52 }))
53
54const convertPart = (part: MP.Part): Multipart.Part =>
55 part._tag === "Field" ? new FieldImpl(part.info, part.value) : new FileImpl(part)

Callers 1

resolver.tsFile · 0.50

Calls 4

streamFunction · 0.70
writeMethod · 0.65
endMethod · 0.65
flushMethod · 0.45

Tested by

no test coverage detected