Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

234
Visualizações
Read and extract parameters from a file using NodeJS

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?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda