Created
March 9, 2020 12:12
-
-
Save barhoring/0615d7b7d45267b7a3711f94fbd1e246 to your computer and use it in GitHub Desktop.
Reads a file and saves a new escaped file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require("fs"); | |
var data = ""; | |
let [inputFileName, ouputFileName] = process.argv.slice(2); | |
[fName, fExtension] = inputFileName.split("."); | |
ouputFileName = ouputFileName | |
? ouputFileName | |
: `${fName}_escaped.${fExtension}`; | |
var readStream = fs.createReadStream(inputFileName, "utf8"); | |
readStream | |
.on("data", function(chunk) { | |
data += chunk; | |
}) | |
.on("end", function() { | |
data = JSON.stringify(data).slice(1, -1); | |
fs.writeFileSync(ouputFileName, data, "utf8"); | |
console.log(`saved escape file: ${ouputFileName}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
node .\saveAsText.js src/App.js src/App_escaped.js
The third parameter (output file name) is optional