Reputation: 101
I am trying to make transform stream to write in object mode, but keep reading strings. Is it possible? Documentation says, that for Duplex stream I can set readableObjectMode and writableObjectMode separately, but somehow it is not working for me. When I use callback with my object in _flush, I get error: Invalid non-string/buffer chunk
Am I doing something wrong or it doesn't work in Transform streams?
Here is my code:
class stream extends Transform {
private logs: { name: string, errors: any[] };
constructor() {
super({ writableObjectMode: true });
this.logs = { name: this.tableName, errors: [] };
}
_transform(chunk, encoding, callback) {
// stuff here
callback();
}
_flush(callback) {
//here I get error
callback(undefined, this.logs);
}
}
Upvotes: 4
Views: 2773
Reputation: 101
I found the answer. I need to set { readableObjectMode: true } instead, because this is actually a readable side of my transform stream that I am using, not writable.
Upvotes: 6