Stream JSON lists to file one line at a time

This commit is contained in:
ThatGuySam 2023-04-01 09:56:14 -05:00
parent ea40288bea
commit d497c12c99

View file

@ -51,6 +51,9 @@ import {
import { import {
cliOptions cliOptions
} from '~/helpers/cli-options.js' } from '~/helpers/cli-options.js'
import {
streamToJson
} from '~/helpers/json.js'
// Setup dotenv // Setup dotenv
dotenv.config() dotenv.config()
@ -279,13 +282,7 @@ class BuildLists {
const saveableList = saveMethod( this.lists[listOptions.name] ) const saveableList = saveMethod( this.lists[listOptions.name] )
// console.log('saveableList', typeof saveableList) await streamToJson( saveableList, listFullPath )
// Stringify one at a time to allow for large lists
const saveableListJSON = '[' + saveableList.map(el => JSON.stringify(el)).join(',') + ']'
// Write the list to JSON
await fs.writeFile(listFullPath, saveableListJSON)
return return
} }