From d497c12c994179296eb83fead2eaf2a168c1f3a6 Mon Sep 17 00:00:00 2001 From: ThatGuySam Date: Sat, 1 Apr 2023 09:56:14 -0500 Subject: [PATCH] Stream JSON lists to file one line at a time --- build-lists.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/build-lists.js b/build-lists.js index b542315..6a0552b 100644 --- a/build-lists.js +++ b/build-lists.js @@ -51,6 +51,9 @@ import { import { cliOptions } from '~/helpers/cli-options.js' +import { + streamToJson +} from '~/helpers/json.js' // Setup dotenv dotenv.config() @@ -279,13 +282,7 @@ class BuildLists { const saveableList = saveMethod( this.lists[listOptions.name] ) - // console.log('saveableList', typeof saveableList) - - // 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) + await streamToJson( saveableList, listFullPath ) return }