diff --git a/.travis.yml b/.travis.yml index 33b2eaf..ad24ec5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,25 @@ language: node_js cache: npm +dist: bionic + +branches: + only: + - master + - /^release\/.*$/ + stages: - check - test - cov node_js: - - '10' - - '12' + - 'lts/*' + - 'node' os: - linux - osx + - windows script: npx nyc -s npm run test:node -- --bail after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov @@ -36,7 +44,7 @@ jobs: name: firefox addons: firefox: latest - script: npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless + script: npx aegir test -t browser -t webworker -- --browser firefox notifications: email: false \ No newline at end of file diff --git a/package.json b/package.json index 1586a54..32347e7 100644 --- a/package.json +++ b/package.json @@ -40,25 +40,27 @@ }, "homepage": "https://github.com/multiformats/js-multistream-select#readme", "dependencies": { - "bl": "^4.0.0", + "bl": "^5.0.0", "debug": "^4.1.1", - "err-code": "^2.0.0", - "it-handshake": "^1.0.2", - "it-length-prefixed": "^3.0.0", + "err-code": "^3.0.1", + "it-first": "^1.0.6", + "it-handshake": "^2.0.0", + "it-length-prefixed": "^5.0.0", "it-pipe": "^1.0.1", - "it-reader": "^2.0.0", + "it-reader": "^3.0.0", "p-defer": "^3.0.0", - "uint8arrays": "^1.1.0" + "uint8arrays": "^2.1.4" }, "devDependencies": { - "aegir": "^25.1.0", + "@types/bl": "^4.1.0", + "aegir": "^33.0.0", "chai": "^4.2.0", "dirty-chai": "^2.0.1", "it-pair": "^1.0.0", "mocha": "^8.1.1", - "p-timeout": "^3.2.0", + "p-timeout": "^4.0.0", "streaming-iterables": "^5.0.2", - "varint": "^5.0.0" + "varint": "^6.0.0" }, "contributors": [ "David Dias ", diff --git a/src/multistream.js b/src/multistream.js index c09cd69..93cdb71 100644 --- a/src/multistream.js +++ b/src/multistream.js @@ -5,13 +5,10 @@ const lp = require('it-length-prefixed') const pipe = require('it-pipe') const errCode = require('err-code') const uint8ArrayFromString = require('uint8arrays/from-string') +const first = require('it-first') const NewLine = uint8ArrayFromString('\n') -async function oneChunk (source) { - for await (const chunk of source) return chunk // We only need one! -} - exports.encode = buffer => lp.encode.single(new BufferList([buffer, NewLine])) // `write` encodes and writes a single buffer @@ -31,7 +28,7 @@ exports.read = async reader => { // Once the length has been parsed, read chunk for that length const onLength = l => { byteLength = l } - const buf = await pipe(varByteSource, lp.decode({ onLength }), oneChunk) + const buf = await pipe(varByteSource, lp.decode({ onLength }), first) if (buf.get(buf.length - 1) !== NewLine[0]) { throw errCode(new Error('missing newline'), 'ERR_INVALID_MULTISTREAM_SELECT_MESSAGE')