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

Function fromList

lib/internal/streams/readable.js:1630–1728  ·  view source on GitHub ↗
(n, state)

Source from the content-addressed store, hash-verified

1628// This function is designed to be inlinable, so please take care when making
1629// changes to the function body.
1630function fromList(n, state) {
1631 // nothing buffered.
1632 if (state.length === 0)
1633 return null;
1634
1635 let idx = state.bufferIndex;
1636 let ret;
1637
1638 const buf = state.buffer;
1639 const len = buf.length;
1640
1641 if ((state[kState] & kObjectMode) !== 0) {
1642 ret = buf[idx];
1643 buf[idx++] = null;
1644 } else if (!n || n >= state.length) {
1645 // Read it all, truncate the list.
1646 if ((state[kState] & kDecoder) !== 0) {
1647 ret = '';
1648 while (idx < len) {
1649 ret += buf[idx];
1650 buf[idx++] = null;
1651 }
1652 } else if (len - idx === 0) {
1653 ret = new FastBuffer();
1654 } else if (len - idx === 1) {
1655 ret = buf[idx];
1656 buf[idx++] = null;
1657 } else {
1658 ret = Buffer.allocUnsafe(state.length);
1659
1660 let i = 0;
1661 while (idx < len) {
1662 TypedArrayPrototypeSet(ret, buf[idx], i);
1663 i += buf[idx].length;
1664 buf[idx++] = null;
1665 }
1666 }
1667 } else if (n < buf[idx].length) {
1668 // `slice` is the same for buffers and strings.
1669 ret = buf[idx].slice(0, n);
1670 buf[idx] = buf[idx].slice(n);
1671 } else if (n === buf[idx].length) {
1672 // First chunk is a perfect match.
1673 ret = buf[idx];
1674 buf[idx++] = null;
1675 } else if ((state[kState] & kDecoder) !== 0) {
1676 ret = '';
1677 while (idx < len) {
1678 const str = buf[idx];
1679 if (n > str.length) {
1680 ret += str;
1681 n -= str.length;
1682 buf[idx++] = null;
1683 } else {
1684 if (n === str.length) {
1685 ret += str;
1686 buf[idx++] = null;
1687 } else {

Callers 1

readable.jsFile · 0.85

Calls 1

sliceMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…