I have a file. I need to append an annotation ( @Circuit(name = backendB) ) if "createEvent" name exists and annotation is not present in that file. I'm not sure how to proceed further. Can anyone help me what is the way to check and append using streams.
async function appendData() {
let file_path = "./File/controller.java"
try {
let txt = "( @Circuit(name = backendB) )"
const readstream = fs.createReadStream(file_path);
const updtstrem = fs.createWriteStream("./FileUpload/auditcontroller_test.java")
readstream
.on("data", (data) => {
let temp = data.toString()
let pos = temp.toString().indexOf("createEvent")
})
}
}
There is a term called "readline". You could use that.
This should work I think. Do let me know if stuck.