问题
I've found an example of a transform stream here that transforms text to uppercase:
Upper.prototype._transform = function (chunk, enc, cb) {
var upperChunk = chunk.toString().toUpperCase();
this.push(upperChunk);
cb();
};
Is my understanding correct that such approach might lead to errors when multi-byte encoding is used because a character bytes can be split between two chunks?
Wouldn't it be better to gather all chunks and then on end transform them? Something like this (not sure it'll work)
var body = [];
request.on('data', function(chunk) {
body.push(chunk);
}).on('end', function() {
this.push(Buffer.concat(body).toString());
});
Is transform function not used in this case?
来源:https://stackoverflow.com/questions/40358449/transforming-text-to-uppercase