From c6f324087010e2ef4451fa12f328df9d5c00348f Mon Sep 17 00:00:00 2001 From: Alexander Penev Date: Mon, 25 Mar 2019 15:28:08 +0200 Subject: [PATCH] Update reads on readable events --- examples/app3.js | 4 ++-- examples/app7.js | 4 ++-- test/acceptance/db.Query.js | 4 ++-- test/lib.Lob.js | 4 ++-- test/lib.ResultSet.js | 8 ++++---- test/lib.ResultSetTransform.js | 12 ++++++------ test/lib.Stringifier.js | 6 +++--- test/util.index.js | 8 ++++++-- 8 files changed, 27 insertions(+), 23 deletions(-) diff --git a/examples/app3.js b/examples/app3.js index 5117f0f..8a0f738 100644 --- a/examples/app3.js +++ b/examples/app3.js @@ -52,8 +52,8 @@ function fetchRows(rs, cb) { function onreadable() { /* jshint validthis:true */ - var chunk = this.read(); - if (chunk) { + var chunk; + while (null !== (chunk = this.read())) { rows.push(chunk); } } diff --git a/examples/app7.js b/examples/app7.js index f1e3c6a..3c95c96 100644 --- a/examples/app7.js +++ b/examples/app7.js @@ -107,8 +107,8 @@ function fetch(rs, cb) { function read() { /* jshint validthis:true */ - var row = this.read(); - if (row) { + var row; + while (null !== (row = this.read())) { rows.push(row); } } diff --git a/test/acceptance/db.Query.js b/test/acceptance/db.Query.js index 341df81..08a620c 100644 --- a/test/acceptance/db.Query.js +++ b/test/acceptance/db.Query.js @@ -73,8 +73,8 @@ describe('db', function () { readable.once('error', function onerror() { done(err); }).on('readable', function onreadable() { - var chunk = this.read(); - if (chunk) { + var chunk; + while (null !== (chunk = this.read())) { rows = rows.concat(chunk); } }).once('end', function onend() { diff --git a/test/lib.Lob.js b/test/lib.Lob.js index dac8b7e..71059d4 100644 --- a/test/lib.Lob.js +++ b/test/lib.Lob.js @@ -95,8 +95,8 @@ describe('Lib', function () { var stream = lob.createReadStream(); var chunks = []; stream.on('readable', function () { - var chunk = stream.read(); - if (chunk) { + var chunk; + while (null !== (chunk = stream.read())) { chunks.push(chunk); } if (chunks.length === 3) { diff --git a/test/lib.ResultSet.js b/test/lib.ResultSet.js index d91a912..0ecd043 100644 --- a/test/lib.ResultSet.js +++ b/test/lib.ResultSet.js @@ -93,10 +93,10 @@ ConnectionMock.prototype.fetchNext = function fetchNext(options, cb) { function readSimpleStream(rs, stream, cb) { var chunks = []; stream.on('readable', function onreadable() { - var chunk = stream.read(); - if (chunk !== null) { - chunks.push(chunk); - } + var chunk; + while (null !== (chunk = stream.read())) { + chunks.push(chunk); + } }); rs.once('error', function onerror(err) { cb(err); diff --git a/test/lib.ResultSetTransform.js b/test/lib.ResultSetTransform.js index 67b51a2..f218a92 100644 --- a/test/lib.ResultSetTransform.js +++ b/test/lib.ResultSetTransform.js @@ -120,8 +120,8 @@ describe('Lib', function () { }); var chunks = []; rst.on('readable', function () { - var value = rst.read(); - if (value !== null) { + var value; + while ((value = rst.read()) !== null) { chunks.push(Buffer.from([value])); } }); @@ -143,8 +143,8 @@ describe('Lib', function () { }); var chunks = []; rst.on('readable', function () { - var value = rst.read(); - if (value !== null) { + var value; + while ((value = rst.read()) !== null) { chunks.push(Buffer.from(value)); } }); @@ -167,8 +167,8 @@ describe('Lib', function () { }); var chunks = []; rst.on('readable', function () { - var value = rst.read(); - if (value !== null) { + var value; + while ((value = rst.read()) !== null) { chunks.push(Buffer.from(value)); } }); diff --git a/test/lib.Stringifier.js b/test/lib.Stringifier.js index 61ee939..aa34c76 100644 --- a/test/lib.Stringifier.js +++ b/test/lib.Stringifier.js @@ -73,11 +73,11 @@ function testStringifier(chunks, rows, done) { stringifier.on('error', function (err) { done(err); }).on('readable', function () { - var chunk = this.read(); - if (chunk) { + var chunk; + while (null !== (chunk = this.read())) { data += chunk; } - }).on('finish', function () { + }).on('end', function () { JSON.parse(data).should.eql(rows); done(); }); diff --git a/test/util.index.js b/test/util.index.js index c09da4b..5279d89 100644 --- a/test/util.index.js +++ b/test/util.index.js @@ -57,10 +57,14 @@ describe('Util', function () { var chunks = []; readable.on('readable', function () { - var chunk = this.read(); - if (chunk !== null) { + var chunk; + var emit = false; + while (null !== (chunk = this.read())) { var value = chunk[0]; chunks.unshift(value); + emit = true; + } + if (emit) { emitData(); } });