From b651ba43745fbf202186467107f25836fc709a1a Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 12 Nov 2019 14:46:19 +0000 Subject: [PATCH] refactor: API tweaks --- README.md | 2 +- package-lock.json | 12 ++++++------ package.json | 4 ++-- src/decode.js | 3 +-- src/index.js | 1 - ...ode.reader.spec.js => decode.from-reader.spec.js} | 4 ++-- 6 files changed, 12 insertions(+), 14 deletions(-) rename test/{decode.reader.spec.js => decode.from-reader.spec.js} (93%) diff --git a/README.md b/README.md index 9cc91e4..2dd289a 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ Returns a `BufferList` containing the encoded chunk. Returns a [transform](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#transform-it) that yields [`BufferList`](https://www.npmjs.com/package/bl) objects. -### `decodeFromReader(reader, [opts])` +### `decode.fromReader(reader, [opts])` Behaves like `decode` except it only reads the exact number of bytes needed for each message in `reader`. diff --git a/package-lock.json b/package-lock.json index 68e81ed..628ab78 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10062,15 +10062,15 @@ } }, "it-pipe": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/it-pipe/-/it-pipe-1.0.1.tgz", - "integrity": "sha512-clx7NMIf4eXe3rp4dKLmT5vMYv/hvZv4lNi1/xx4ZJ8CFmpGod9rTKisyBNBTurbCEa3a7503COankdBj/uUCA==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/it-pipe/-/it-pipe-1.1.0.tgz", + "integrity": "sha512-lF0/3qTVeth13TOnHVs0BTFaziwQF7m5Gg+E6JV0BXcLKutC92YjSi7bASgkPOXaLEb+YvNZrPorGMBIJvZfxg==", "dev": true }, "it-pushable": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/it-pushable/-/it-pushable-1.3.2.tgz", - "integrity": "sha512-Gk9/WJRPPgHizId9jqc0n1jXrzhCoutB4K6Wr8KiJQI88h0yBI4LWbu7PBFpqFdGZ0xTuV8Luy5IpeSy5mzIUw==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/it-pushable/-/it-pushable-1.4.0.tgz", + "integrity": "sha512-W7251Tj88YBqUIEDWCwd3F8JettSbze+bBp5B3ASzz5tYWaLUI1VDNGbjllH1T6RJ71a5jUSTSt5vHjvuzwoFw==", "dev": true, "requires": { "fast-fifo": "^1.0.0" diff --git a/package.json b/package.json index 18f4d12..14e21f7 100644 --- a/package.json +++ b/package.json @@ -42,8 +42,8 @@ "aegir": "^20.3.1", "chai": "^4.2.0", "it-block": "^2.0.0", - "it-pipe": "^1.0.1", - "it-pushable": "^1.3.1", + "it-pipe": "^1.1.0", + "it-pushable": "^1.4.0", "it-reader": "^2.0.0", "p-defer": "^3.0.0", "random-bytes": "^1.0.0", diff --git a/src/decode.js b/src/decode.js index 75b4699..47b9528 100644 --- a/src/decode.js +++ b/src/decode.js @@ -100,7 +100,7 @@ function decode (options) { })() } -function decodeFromReader (reader, options) { +decode.fromReader = (reader, options) => { options = options || {} let byteLength = 1 // Read single byte chunks until the length is known @@ -127,5 +127,4 @@ function decodeFromReader (reader, options) { } module.exports = decode -module.exports.decodeFromReader = decodeFromReader module.exports.MAX_DATA_LENGTH = MAX_DATA_LENGTH diff --git a/src/index.js b/src/index.js index d65ff37..aa271e4 100644 --- a/src/index.js +++ b/src/index.js @@ -2,4 +2,3 @@ exports.encode = require('./encode') exports.decode = require('./decode') -exports.decodeFromReader = exports.decode.decodeFromReader diff --git a/test/decode.reader.spec.js b/test/decode.from-reader.spec.js similarity index 93% rename from test/decode.reader.spec.js rename to test/decode.from-reader.spec.js index ba152cb..b658107 100644 --- a/test/decode.reader.spec.js +++ b/test/decode.from-reader.spec.js @@ -22,7 +22,7 @@ describe('decode from reader', () => { ) const output = await pipe( - lp.decodeFromReader(reader), + lp.decode.fromReader(reader), toBuffer, collect ) @@ -42,7 +42,7 @@ describe('decode from reader', () => { const reader = Reader(input) try { await pipe( - lp.decodeFromReader(reader, { maxDataLength: 100 }), + lp.decode.fromReader(reader, { maxDataLength: 100 }), toBuffer, collect )