| 25515 | // mode the stream is in. Currently this means that `null` is never accepted |
| 25516 | // and undefined/non-string values are only allowed in object mode. |
| 25517 | function validChunk(stream, state, chunk, cb) { |
| 25518 | var valid = true; |
| 25519 | var er = false; |
| 25520 | |
| 25521 | if (chunk === null) { |
| 25522 | er = new TypeError('May not write null values to stream'); |
| 25523 | } else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) { |
| 25524 | er = new TypeError('Invalid non-string/buffer chunk'); |
| 25525 | } |
| 25526 | if (er) { |
| 25527 | stream.emit('error', er); |
| 25528 | processNextTick(cb, er); |
| 25529 | valid = false; |
| 25530 | } |
| 25531 | return valid; |
| 25532 | } |
| 25533 | |
| 25534 | Writable.prototype.write = function (chunk, encoding, cb) { |
| 25535 | var state = this._writableState; |