| 787 | } |
| 788 | |
| 789 | write(chunk, encoding, cb) { |
| 790 | const state = this[kState]; |
| 791 | |
| 792 | if (typeof encoding === 'function') { |
| 793 | cb = encoding; |
| 794 | encoding = 'utf8'; |
| 795 | } |
| 796 | |
| 797 | let err; |
| 798 | if (state.ending) { |
| 799 | err = new ERR_STREAM_WRITE_AFTER_END(); |
| 800 | } else if (state.closed) { |
| 801 | err = new ERR_HTTP2_INVALID_STREAM(); |
| 802 | } else if (state.destroyed) { |
| 803 | return false; |
| 804 | } |
| 805 | |
| 806 | if (err) { |
| 807 | if (typeof cb === 'function') |
| 808 | process.nextTick(cb, err); |
| 809 | this.destroy(err); |
| 810 | return false; |
| 811 | } |
| 812 | |
| 813 | const stream = this[kStream]; |
| 814 | if (!stream.headersSent) |
| 815 | this.writeHead(state.statusCode); |
| 816 | return stream.write(chunk, encoding, cb); |
| 817 | } |
| 818 | |
| 819 | end(chunk, encoding, cb) { |
| 820 | const stream = this[kStream]; |