MCPcopy
hub / github.com/ThatGuySam/doesitarm / streamToJson

Function streamToJson

helpers/json.js:7–33  ·  view source on GitHub ↗
( dataArray, filePath )

Source from the content-addressed store, hash-verified

5// that would not normal fit into memory
6// or V8 string size limits
7export function streamToJson ( dataArray, filePath ) {
8 return new Promise( resolve => {
9 const output = fs.createWriteStream( filePath, 'utf8' )
10
11 // When the stream is finished
12 output.on( 'finish', () => {
13 resolve( output )
14 })
15
16 // Write opening array bracket
17 output.write( '[' )
18
19 // Write each item in the array
20 for ( const item of dataArray ) {
21 output.write( JSON.stringify( item ) + ',' )
22 }
23
24 // Write closing array bracket
25 output.write( ']' )
26
27 // Close the stream
28 output.end()
29
30 // Return the stream
31 return output
32 })
33}

Callers 1

BuildListsClass · 0.90

Calls 1

onMethod · 0.80

Tested by

no test coverage detected