diff --git a/README.MD b/README.MD index 771248c..35fb28b 100644 --- a/README.MD +++ b/README.MD @@ -39,7 +39,8 @@ Global install to have the CLI accessible from everywhere on your operating syst npm install -g turbo-json.js # install globaly ``` -No installation needed when using `npx`. +No installation needed when using [npx](https://www.npmjs.com/package/npx). + ```bash npx turbo-json.js [options] ``` diff --git a/misc/empty_obj_and_array/empty_array.json b/misc/empty_obj_and_array/empty_array.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/misc/empty_obj_and_array/empty_array.json @@ -0,0 +1 @@ +[] diff --git a/misc/empty_obj_and_array/empty_obj.json b/misc/empty_obj_and_array/empty_obj.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/misc/empty_obj_and_array/empty_obj.json @@ -0,0 +1 @@ +{} diff --git a/misc/special_char_jsons/normal_array.json b/misc/special_char_jsons/normal_array.json new file mode 100644 index 0000000..414daa0 --- /dev/null +++ b/misc/special_char_jsons/normal_array.json @@ -0,0 +1,3 @@ +[ + "hello" +] diff --git a/misc/special_char_jsons/russian_array.json b/misc/special_char_jsons/russian_array.json new file mode 100644 index 0000000..8476fbe --- /dev/null +++ b/misc/special_char_jsons/russian_array.json @@ -0,0 +1,3 @@ +[ + "Лорем ипсум долор сит амет" +] diff --git a/src/cli.js b/src/cli.js index 2581f12..ff4d470 100755 --- a/src/cli.js +++ b/src/cli.js @@ -24,7 +24,12 @@ program 'Check if output JSON is a valid JSON', false ) - .option('-q, --quiet', 'Quiet mode, no logs are outputed', true) + .option('-q, --quiet', 'Quiet mode, no logs are outputed', false) + .option( + '-b, --buffer-size ', + 'Size of the buffer containing the maximum data kept in memory at any time', + 1000 + ) .action(async (directory, options) => { await combineJson(directory, options) }) diff --git a/src/combine-json.js b/src/combine-json.js index e6cea27..52da229 100755 --- a/src/combine-json.js +++ b/src/combine-json.js @@ -16,8 +16,6 @@ const { logFailedOutputValidityCheck, } = require('./log') -const BUFFER_SIZE = 1000 - async function combine({ inputFiles, inputDirPath, @@ -25,6 +23,7 @@ async function combine({ validateInput, validateOutput, quiet, + bufferSize, }) { createOutputArrayFile(outputFilePath) const numberOfFiles = inputFiles.length @@ -41,7 +40,7 @@ async function combine({ const { isArray, startPosition, empty } = jsonRootType({ fd: inputFileFd, - bufferSize: BUFFER_SIZE, + bufferSize: bufferSize, }) let stopPosition = undefined @@ -49,11 +48,12 @@ async function combine({ if (isArray) { stopPosition = closingArrayIndex({ fd: inputFileFd, + position: - fileSize(inputFile) - BUFFER_SIZE > 0 - ? fileSize(inputFile) - BUFFER_SIZE + fileSize(inputFile) - bufferSize > 0 + ? fileSize(inputFile) - bufferSize : 0, - bufferSize: BUFFER_SIZE, + bufferSize: bufferSize, }) } @@ -132,6 +132,7 @@ async function combineJson( validateInput = false, validateOutput = false, quiet = false, + bufferSize = 1000, } ) { const { inputDirPath, filesName } = inputFilesAndDir({ inputDir }) @@ -144,6 +145,7 @@ async function combineJson( validateInput, validateOutput, quiet, + bufferSize, }) } diff --git a/src/json-root-type.js b/src/json-root-type.js index f801d8e..4ea6160 100644 --- a/src/json-root-type.js +++ b/src/json-root-type.js @@ -22,7 +22,6 @@ function findClosingArrayIndex({ fd, buffer, position }) { function closingArrayIndex({ fd, position, bufferSize = 1000 }) { let buffer = new Int8Array(bufferSize) - return findClosingArrayIndex({ fd, buffer, position }) } diff --git a/src/log.js b/src/log.js index b9a7c52..67637db 100644 --- a/src/log.js +++ b/src/log.js @@ -5,7 +5,7 @@ const logSuccessfullWrite = (fileName, index, numberOfFiles) => { chalk.green( 'file: ' + chalk.blue.underline.bold(fileName) + - ` has been added! index: ${index}, number of files: ${numberOfFiles}` + ` has been added! index: ${index}/${numberOfFiles}` ) ) }