i´m writting a little parser in nodejs which translates a given assembly language into binary code. Ironically I struggle with the line reading. What I want is the possibility to read a file line by line (like the readline.createInterface) Module BUT it should only advance in lines when I invoke a function.
I.E
1.) While LastChunkNotReached
1.1) Read chunk
1.2) Split chunk into lines and save into buffer
2.) While last line in buffer not reached
2.1) return actual line somehow and wait for the user to invoke a function to
advance to the next line.
2.) End
1.) End
In case of the readable event (which may be the only valid starting point for me) you can gather the chunks while invoking the stream.read() function.
stream.on("readable", () => {
console.log("Data available");
const data = stream.read();
console.log("Data read: " + data)
})
But the problem with this approach is the following (as far as I observed it): When I use the read function, it returns a chunk from the internal buffer, but now the readable event gets fired everytime the internal buffer has new fresh data (which in turn calls the .read() function)
Is there a clean way to intercept this behaviour to get to the point which I described above? Would be nice if you can give me some thoughts or tips about this problem!