summaryrefslogtreecommitdiff
path: root/lib/_stream_readable.js
diff options
context:
space:
mode:
authorLuigi Pinca <luigipinca@gmail.com>2018-01-24 18:45:51 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2018-02-01 10:58:35 +0100
commitccf64e5f222a51349d5d81784c869ab2b940c4d1 (patch)
treeb6bba0f6aaa736e83c9f73b64d28d930915109aa /lib/_stream_readable.js
parent5898dc3d0c071a8e5135ba0a80565dd19d49cb32 (diff)
downloadandroid-node-v8-ccf64e5f222a51349d5d81784c869ab2b940c4d1.tar.gz
android-node-v8-ccf64e5f222a51349d5d81784c869ab2b940c4d1.tar.bz2
android-node-v8-ccf64e5f222a51349d5d81784c869ab2b940c4d1.zip
stream: augment BufferList.prototype
Move functions that deal with `BufferList` to `BufferList.prototype`. PR-URL: https://github.com/nodejs/node/pull/18353 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib/_stream_readable.js')
-rw-r--r--lib/_stream_readable.js92
1 files changed, 2 insertions, 90 deletions
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index 6854b3d9eb..19e9e7a743 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -987,106 +987,18 @@ function fromList(n, state) {
if (state.decoder)
ret = state.buffer.join('');
else if (state.buffer.length === 1)
- ret = state.buffer.head.data;
+ ret = state.buffer.first();
else
ret = state.buffer.concat(state.length);
state.buffer.clear();
} else {
// read part of list
- ret = fromListPartial(n, state.buffer, state.decoder);
+ ret = state.buffer.consume(n, state.decoder);
}
return ret;
}
-// Extracts only enough buffered data to satisfy the amount requested.
-// This function is designed to be inlinable, so please take care when making
-// changes to the function body.
-function fromListPartial(n, list, hasStrings) {
- var ret;
- if (n < list.head.data.length) {
- // slice is the same for buffers and strings
- ret = list.head.data.slice(0, n);
- list.head.data = list.head.data.slice(n);
- } else if (n === list.head.data.length) {
- // first chunk is a perfect match
- ret = list.shift();
- } else {
- // result spans more than one buffer
- ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
- }
- return ret;
-}
-
-// Copies a specified amount of characters from the list of buffered data
-// chunks.
-// This function is designed to be inlinable, so please take care when making
-// changes to the function body.
-function copyFromBufferString(n, list) {
- var p = list.head;
- var c = 1;
- var ret = p.data;
- n -= ret.length;
- while (p = p.next) {
- const str = p.data;
- const nb = (n > str.length ? str.length : n);
- if (nb === str.length)
- ret += str;
- else
- ret += str.slice(0, n);
- n -= nb;
- if (n === 0) {
- if (nb === str.length) {
- ++c;
- if (p.next)
- list.head = p.next;
- else
- list.head = list.tail = null;
- } else {
- list.head = p;
- p.data = str.slice(nb);
- }
- break;
- }
- ++c;
- }
- list.length -= c;
- return ret;
-}
-
-// Copies a specified amount of bytes from the list of buffered data chunks.
-// This function is designed to be inlinable, so please take care when making
-// changes to the function body.
-function copyFromBuffer(n, list) {
- const ret = Buffer.allocUnsafe(n);
- var p = list.head;
- var c = 1;
- p.data.copy(ret);
- n -= p.data.length;
- while (p = p.next) {
- const buf = p.data;
- const nb = (n > buf.length ? buf.length : n);
- buf.copy(ret, ret.length - n, 0, nb);
- n -= nb;
- if (n === 0) {
- if (nb === buf.length) {
- ++c;
- if (p.next)
- list.head = p.next;
- else
- list.head = list.tail = null;
- } else {
- list.head = p;
- p.data = buf.slice(nb);
- }
- break;
- }
- ++c;
- }
- list.length -= c;
- return ret;
-}
-
function endReadable(stream) {
var state = stream._readableState;