MCPcopy Create free account
hub / github.com/omkarcloud/botasaurus / writeJson

Function writeJson

js/botasaurus-server-js/src/writer.ts:90–118  ·  view source on GitHub ↗
(data: any, filename: string)

Source from the content-addressed store, hash-verified

88
89
90async function writeJson(data: any, filename: string): Promise<string> {
91 try {
92 filename = trimFilename(filename)
93
94 if (!filename.endsWith('.json')) {
95 filename = filename + '.json'
96 }
97
98 const writer = new JSONWriteStream(filename)
99 await writer.preStart()
100
101 for (let index = 0; index < data.length; index++) {
102 const element = data[index];
103 applyFunctionToResult(element, async (x)=>{
104 await writer.push(x)
105 })
106
107 }
108 await writer.end()
109
110 } catch (error: any) {
111 if (isFileOpenError(error)) {
112 const baseFilename = path.basename(filename)
113 throw new Error(`${baseFilename} is currently open in another application. Please close the application and try again.`)
114 }
115 throw error
116 }
117 return filename
118}
119
120
121function fixCsvFilename(filename: string): string {

Callers 2

downloadResultsFunction · 0.90
index.jsFile · 0.50

Calls 6

preStartMethod · 0.95
pushMethod · 0.95
trimFilenameFunction · 0.85
applyFunctionToResultFunction · 0.85
isFileOpenErrorFunction · 0.70
endMethod · 0.45

Tested by

no test coverage detected