MCPcopy Index your code
hub / github.com/nodejs/node / #writeBuffer

Method #writeBuffer

lib/internal/streams/fast-utf8-stream.js:799–836  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

797 }
798
799 #writeBuffer(data) {
800 if (this.#destroyed) {
801 throw new ERR_INVALID_STATE('Utf8Stream is destroyed');
802 }
803
804 // TODO(@jasnell): Support any ArrayBufferView type here, not just Buffer.
805 if (!Buffer.isBuffer(data)) {
806 throw new ERR_INVALID_ARG_TYPE('data', 'Buffer', data);
807 }
808
809 const len = this.#len + data.length;
810 const bufs = this.#bufs;
811 const lens = this.#lens;
812
813 if (this.#maxLength && len > this.#maxLength) {
814 this.emit('drop', data);
815 return this.#len < this.#hwm;
816 }
817
818 if (
819 bufs.length === 0 ||
820 lens[lens.length - 1] + data.length > this.#maxWrite
821 ) {
822 ArrayPrototypePush(bufs, [data]);
823 ArrayPrototypePush(lens, data.length);
824 } else {
825 ArrayPrototypePush(bufs[bufs.length - 1], data);
826 lens[lens.length - 1] += data.length;
827 }
828
829 this.#len = len;
830
831 if (!this.#writing && this.#len >= this.#minLength) {
832 this.#actualWrite();
833 }
834
835 return this.#len < this.#hwm;
836 }
837
838 #writeUtf8(data) {
839 if (this.#destroyed) {

Callers 1

constructorMethod · 0.95

Calls 1

emitMethod · 0.45

Tested by

no test coverage detected