How to add chunk to variable while reading a readable stream in node?

10 Views Asked by At
readDir(input).then(function(data) {
  let rowIndex
  let remarkIndex;
  let count = 0
  let currentIntrest = 0
  var fileStreams = data.map((file) => {
    return fs.createReadStream("assets/" + file, 'utf-8')
  })
  fileStreams.forEach((stream) => {
    stream.pipe(parser).on('readable', function() {
      let data;
      while ((data = this.read()) !== null) {
        // console.log(data)
        if (data.includes('Credit')) {
          rowIndex = data.indexOf('Credit')
          // console.log(rowIndex)
        }
        if (data.includes('Remarks')) {
          remarkIndex = data.indexOf("Remarks")
          // console.log(remarkIndex)
        }
        if (data[remarkIndex]) {
          count += 1
          const result = data[remarkIndex].startsWith("Int")
          if (result && data[rowIndex])
            currentIntrest = ((data[rowIndex] + " " + data[remarkIndex]))
        }
      }
    })
  })
  console.log(count)
  console.log(currentIntrest)
}).catch(error => console.log(error))

even after getting data[rowIndex] i'm unable to assign or add it to a variable. i'm trying to accumulate the intrest amount which i filtered.

0

There are 0 best solutions below