This commit is contained in:
Jan Prochazka
2024-11-15 16:48:33 +01:00
parent c5d23410f4
commit 81e4b947b6
9 changed files with 58 additions and 11 deletions

View File

@@ -85,6 +85,16 @@ class StringifyStream extends stream.Transform {
}
}
/**
* Returns writer object for {@link copyStream} function. This writer object writes data to JSON file.
* @param {object} options
* @param {string} options.fileName - file name
* @param {string} [options.jsonStyle] - 'object' or 'array'
* @param {string} [options.keyField] - key field for object style
* @param {string} [options.rootField] - root field for object style
* @param {string} [options.encoding] - encoding of the file
* @returns {Promise<writerType>} - writer object
*/
async function jsonWriter({ fileName, jsonStyle, keyField = '_key', rootField, encoding = 'utf-8' }) {
logger.info(`Writing file ${fileName}`);
const stringify = new StringifyStream({ jsonStyle, keyField, rootField });