4

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);
  }
}

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.