Skip to content

Error: Encoding not being detected #13

@rogeriopvl

Description

@rogeriopvl

I'm using csv-stream with express to parse a request stream (file).

This is the code I'm using:

const csv = require('csv-stream')

module.exports = (req, res) => {
  const csvStream = csv.createStream({ enclosedChar: '"' })

  req.pipe(csvStream)
    .on('error', (err) => { console.error(err) })
    .on('data', (data) => { console.log(data) })

  req.on('end', () => { res.send('END') })
}

When I run this, I get this error:

buffer.js:557
  throw new TypeError('Unknown encoding: ' + encoding);
  ^

TypeError: Unknown encoding:
    at stringSlice (buffer.js:557:9)
    at Buffer.toString (buffer.js:593:10)
    at CSVStream.write (/(...)/node_modules/csv-stream/index.js:59:34)
    at IncomingMessage.ondata (_stream_readable.js:626:20)
    at emitOne (events.js:115:13)
    at IncomingMessage.emit (events.js:210:7)
    at IncomingMessage.Readable.read (_stream_readable.js:462:10)
    at flow (_stream_readable.js:833:34)
    at resume_ (_stream_readable.js:815:3)
    at _combinedTickCallback (internal/process/next_tick.js:102:11)

I can fix this by adding the following to my code:

csvStream._encoding = 'utf8'

But this is an ugly hack that I want to avoid at all cost.

Is there any way to fix this from my side? Am I missing something? Or should csv-stream set a value for this._encoding coming from options or something similar?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions