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

367
Visualizações
Nodejs, el flujo legible, no emite un evento de 'finalización'

Creo un flujo de Buffer y Readable , con el objetivo de hacer que Readable consuma el Buffer .

El código es así:

 const { Readable } = require('stream'); // create a Buffer and allocate 200 positions to add the long text const buf = Buffer.alloc(200, 'this is a loooong text..'); const readStream = (buf_data) => { return new Readable({ read(size){ // I push the chunk data to the stream this.push(buf_data); // Here there MUST be a condition that will `push(null)` // end emit the 'end' event // ???? } }) } // Pass the Buffer to the readable stream read = readStream(buf) // the 'data' event is called to print the chunk data read.on('data', (chunk) => { console.log('chnk:', chunk.toString()) }) // the 'end' event, currently is not emitted, and the reading is not stopping. read.on('and', (chunk) => { console.log('--end--') })

Cuando ejecuto la aplicación (nodo <filename> ), la aplicación sigue leyendo e imprimiendo el text . Debería haber una condición que pueda agregar al método read() para hacer que el evento end se active**

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Terminé simplemente emitiendo manualmente el evento end después de crear la transmisión

 let buffer = Buffer.from(attach.base64Data, 'base64'); const bufferStream = Readable.from(buffer) bufferStream.emit("end");

También vale la pena señalar que estuve perplejo por un tiempo porque estaba escuchando finished en lugar de end .

 .on('end',()=>{}) // this gets called .on('finish',()=>{}) // this never gets called.
about 4 years ago · Juan Pablo Isaza Relatório
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