Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

0.11: Writable stream _write gets called with 'buffer' encoding #6119

Closed
hueniverse opened this issue Aug 24, 2013 · 2 comments
Closed

0.11: Writable stream _write gets called with 'buffer' encoding #6119

hueniverse opened this issue Aug 24, 2013 · 2 comments

Comments

@hueniverse
Copy link

var stream = require('stream');
var util = require('util');

var Peek = function () {
    stream.Writable.call(this);
};

util.inherits(Peek, stream.Writable);

Peek.prototype._write = function (chunk, encoding, callback) {
    console.log(encoding);
    callback();
};

var preview = new Peek();
preview.write('some text', 'utf-8');
preview.end();
preview.removeAllListeners();

In node 0.10.17:

utf-8

in node 0.11.6:

buffer
@isaacs
Copy link

isaacs commented Aug 27, 2013

This is working as intended in v0.11. It's actually a Buffer object in both cases. The bug is that v0.10 is passing the encoding along even though it's been buffer-ified.

The intent of this API is so that users don't have to worry about the encoding most of the time. If you want to preserve the strings instead of decoding them into the raw bytes in a buffer, you can do it this way:

var Peek = function (options) {
  options = options || {};
  options.decodeStrings = false;
  stream.Writable.call(this, options);
};

util.inherits(Peek, stream.Writable);

Working on the actual bug now.

@hueniverse
Copy link
Author

Thanks.

isaacs added a commit to isaacs/node-v0.x-archive that referenced this issue Aug 27, 2013
Since the encoding is no longer relevant once it is decoded to a Buffer,
it is confusing and incorrect to pass the encoding as 'utf8' or whatever
in those cases.

Closes nodejs#6119
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants