I am writing a parser that takes a text file and returns an object. The file looks like this:
Val1 3 x 1 - i
0 t
has
Val2 2 r hgs * i
0 t
Now the information comes in groups of lines. First, the first 3 lines, second, the next 2 lines. This I'd be able to tell how many lines the group has from some data (say numbers 2, 3 in the first line of each group).
The result would be:
result = {Val1:{p1:v1, p2:v2}, Val2:{...}}
Where none of the Val<X> keys would be repeated in the source file.
I've written a simple code that would do this, this is just the basic scheme:
const file = fs.readFileSync(path); //array buffer
const arr = file.toString('utf8').split('\n')
And then I iterate over the array.
Now this program will send information from server back the client browser so it should run reasonably fast.
Is this a fast technique that you'd use? Or is there some other built-in way that would be faster?