Skip to content

Instantly share code, notes, and snippets.

@barhoring
Created March 9, 2020 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barhoring/0615d7b7d45267b7a3711f94fbd1e246 to your computer and use it in GitHub Desktop.
Save barhoring/0615d7b7d45267b7a3711f94fbd1e246 to your computer and use it in GitHub Desktop.
Reads a file and saves a new escaped file
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}`);
});
@barhoring
Copy link
Author

node .\saveAsText.js src/App.js src/App_escaped.js

The third parameter (output file name) is optional

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment