MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / copyFromBuffer

Function copyFromBuffer

lib/models/dav.js:5753–5778  ·  view source on GitHub ↗
(n, list)

Source from the content-addressed store, hash-verified

5751// This function is designed to be inlinable, so please take care when making
5752// changes to the function body.
5753function copyFromBuffer(n, list) {
5754 var ret = Buffer.allocUnsafe(n);
5755 var p = list.head;
5756 var c = 1;
5757 p.data.copy(ret);
5758 n -= p.data.length;
5759 while (p = p.next) {
5760 var buf = p.data;
5761 var nb = n > buf.length ? buf.length : n;
5762 buf.copy(ret, ret.length - n, 0, nb);
5763 n -= nb;
5764 if (n === 0) {
5765 if (nb === buf.length) {
5766 ++c;
5767 if (p.next) list.head = p.next;else list.head = list.tail = null;
5768 } else {
5769 list.head = p;
5770 p.data = buf.slice(nb);
5771 }
5772 break;
5773 }
5774 ++c;
5775 }
5776 list.length -= c;
5777 return ret;
5778}
5779
5780function endReadable(stream) {
5781 var state = stream._readableState;

Callers 1

fromListPartialFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected