MCPcopy Index your code
hub / github.com/anomalyco/opencode / write

Function write

packages/opencode/src/util/filesystem.ts:61–80  ·  view source on GitHub ↗
(p: string, content: string | Buffer | Uint8Array, mode?: number)

Source from the content-addressed store, hash-verified

59}
60
61export async function write(p: string, content: string | Buffer | Uint8Array, mode?: number): Promise<void> {
62 try {
63 if (mode) {
64 await writeFile(p, content, { mode })
65 } else {
66 await writeFile(p, content)
67 }
68 } catch (e) {
69 if (isEnoent(e)) {
70 await mkdir(dirname(p), { recursive: true })
71 if (mode) {
72 await writeFile(p, content, { mode })
73 } else {
74 await writeFile(p, content)
75 }
76 return
77 }
78 throw e
79 }
80}
81
82export async function writeJson(p: string, data: unknown, mode?: number): Promise<void> {
83 return write(p, JSON.stringify(data, null, 2), mode)

Callers 1

writeJsonFunction · 0.70

Calls 1

isEnoentFunction · 0.85

Tested by

no test coverage detected