Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Encoding not being detected #13

Open
rogeriopvl opened this issue Jun 20, 2017 · 1 comment
Open

Error: Encoding not being detected #13

rogeriopvl opened this issue Jun 20, 2017 · 1 comment

Comments

@rogeriopvl
Copy link

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?

@orangejulius
Copy link

For me this issue occurs after upgrading to Node.js 8. Both the fix here and in #14 appear to fix it.

orangejulius added a commit to pelias/whosonfirst that referenced this issue Oct 30, 2017
As of Node.js 8, the default encoding value used by the (very old)
csv-stream module is not accepted.

As mentioned in lbdremy/node-csv-stream#13,
explicitly setting the encoding is enough to work around the issue.
orangejulius added a commit to pelias/whosonfirst that referenced this issue Oct 30, 2017
As of Node.js 8, the default encoding value used by the (very old)
csv-stream module is not accepted.

As mentioned in lbdremy/node-csv-stream#13,
explicitly setting the encoding to undefined is enough to work around
the issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants