MCPcopy Index your code
hub / github.com/nodejs/node / write

Method write

lib/internal/http2/compat.js:789–817  ·  view source on GitHub ↗
(chunk, encoding, cb)

Source from the content-addressed store, hash-verified

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];

Callers 1

endMethod · 0.95

Calls 2

destroyMethod · 0.95
writeHeadMethod · 0.95

Tested by

no test coverage detected