From 922147b6668343f41bd2c26c0e46e134b11ad698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiago=20Martins=20N=C3=A1poli?= Date: Fri, 26 Jun 2020 17:54:24 -0300 Subject: [PATCH 1/8] Use native stream.pipeline instead of pump MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tiago Martins Nápoli --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 71f3991..2e7404f 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ 'use strict'; const {constants: BufferConstants} = require('buffer'); -const pump = require('pump'); +const {pipeline} = require('stream'); const bufferStream = require('./buffer-stream'); class MaxBufferError extends Error { @@ -22,7 +22,7 @@ async function getStream(inputStream, options) { const {maxBuffer} = options; - let stream; + const stream = bufferStream(options); await new Promise((resolve, reject) => { const rejectPromise = error => { // Don't retrieve an oversized buffer. @@ -33,7 +33,7 @@ async function getStream(inputStream, options) { reject(error); }; - stream = pump(inputStream, bufferStream(options), error => { + pipeline(inputStream, stream, error => { if (error) { rejectPromise(error); return; From c816dc9737d425d5d5e35c3e3d1cfdeb1d7cd7d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiago=20Martins=20N=C3=A1poli?= Date: Fri, 26 Jun 2020 20:21:54 -0300 Subject: [PATCH 2/8] Remove pump dependency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tiago Martins Nápoli --- package.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/package.json b/package.json index e2f1687..1886eff 100644 --- a/package.json +++ b/package.json @@ -37,9 +37,7 @@ "array", "object" ], - "dependencies": { - "pump": "^3.0.0" - }, + "dependencies": {}, "devDependencies": { "@types/node": "^12.0.7", "ava": "^2.0.0", From f1fb72b9526e0b7a33917f6458c6321007f05728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiago=20Martins=20N=C3=A1poli?= Date: Fri, 26 Jun 2020 17:59:12 -0300 Subject: [PATCH 3/8] engine: require node >= 10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tiago Martins Nápoli --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1886eff..d88178a 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "url": "https://sindresorhus.com" }, "engines": { - "node": ">=8" + "node": ">=10" }, "scripts": { "test": "xo && ava && tsd" From bb59a1a3b93ece57f3f33d9727fc998656b5f9df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiago=20Martins=20N=C3=A1poli?= Date: Fri, 26 Jun 2020 17:57:44 -0300 Subject: [PATCH 4/8] Use throw instead of promise.reject MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tiago Martins Nápoli --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 2e7404f..53834be 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,7 @@ class MaxBufferError extends Error { async function getStream(inputStream, options) { if (!inputStream) { - return Promise.reject(new Error('Expected a stream')); + throw new Error('Expected a stream'); } options = { From 26be719c4ee72294b6e09d4c2727f5901f2e4b4b Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 4 Jul 2020 02:48:34 +0800 Subject: [PATCH 5/8] Update package.json --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index d88178a..a2c0f9c 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,6 @@ "array", "object" ], - "dependencies": {}, "devDependencies": { "@types/node": "^12.0.7", "ava": "^2.0.0", From 18ada3dd4b68f8aa41ec2c7c409420073f4c0e58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiago=20Martins=20N=C3=A1poli?= Date: Fri, 3 Jul 2020 17:04:04 -0300 Subject: [PATCH 6/8] Use promisify MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tiago Martins Nápoli --- index.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 53834be..16c56eb 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,11 @@ 'use strict'; const {constants: BufferConstants} = require('buffer'); const {pipeline} = require('stream'); +const {promisify} = require('util'); const bufferStream = require('./buffer-stream'); +const streamPipelinePromisified = promisify(pipeline); + class MaxBufferError extends Error { constructor() { super('maxBuffer exceeded'); @@ -33,14 +36,7 @@ async function getStream(inputStream, options) { reject(error); }; - pipeline(inputStream, stream, error => { - if (error) { - rejectPromise(error); - return; - } - - resolve(); - }); + streamPipelinePromisified(inputStream, stream).then(resolve, rejectPromise); stream.on('data', () => { if (stream.getBufferedLength() > maxBuffer) { From c3f86e4b2268a814f96ecb23c769867ec511e6e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiago=20Martins=20N=C3=A1poli?= Date: Wed, 15 Jul 2020 17:19:34 -0300 Subject: [PATCH 7/8] Change import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tiago Martins Nápoli --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 16c56eb..2772603 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,10 @@ 'use strict'; const {constants: BufferConstants} = require('buffer'); -const {pipeline} = require('stream'); +const stream = require('stream'); const {promisify} = require('util'); const bufferStream = require('./buffer-stream'); -const streamPipelinePromisified = promisify(pipeline); +const streamPipelinePromisified = promisify(stream.pipeline); class MaxBufferError extends Error { constructor() { From 3dcce61aac042712dd96f13126658a1dc9bc37f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiago=20Martins=20N=C3=A1poli?= Date: Sun, 9 Aug 2020 21:19:33 -0300 Subject: [PATCH 8/8] Use async IIFE inside promise executor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tiago Martins Nápoli --- index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 2772603..71a1ad9 100644 --- a/index.js +++ b/index.js @@ -36,7 +36,14 @@ async function getStream(inputStream, options) { reject(error); }; - streamPipelinePromisified(inputStream, stream).then(resolve, rejectPromise); + (async () => { + try { + await streamPipelinePromisified(inputStream, stream); + resolve(); + } catch (error) { + rejectPromise(error); + } + })(); stream.on('data', () => { if (stream.getBufferedLength() > maxBuffer) {