From 96e89d8f7b43f36c7b931d4ca1e9683f0ea8aa84 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Thu, 10 May 2018 12:26:06 -0600 Subject: [PATCH] chore: remove unused file --- src/utils.js | 46 -------------------------- test/mplex.spec.js | 82 ---------------------------------------------- 2 files changed, 128 deletions(-) delete mode 100644 src/utils.js delete mode 100644 test/mplex.spec.js diff --git a/src/utils.js b/src/utils.js deleted file mode 100644 index f399bfb..0000000 --- a/src/utils.js +++ /dev/null @@ -1,46 +0,0 @@ -'use strict' - -const pull = require('pull-stream') -const varint = require('varint') -const lp = require('pull-length-prefixed') -const cat = require('pull-cat') -const through = require('pull-through') - -exports.encodeMsg = (id, type, data, cb) => { - return pull( - cat([ - pull.values([varint.encode(id << 3 | type)]), - pull( - pull.values([Buffer.from(data)]), - lp.encode() - ) - ]), - pull.flatten(), - pull.collect((err, data) => { - if (err) { return cb(err) } - cb(null, Buffer.from(data)) - }) - ) -} - -exports.decodeMsg = (msg, cb) => { - return pull( - cat([ - pull( - pull.values([msg.slice(0, 1)]), - through(function (h) { - const header = varint.decode(h) - this.queue({ id: header >> 3, type: header & 7 }) - }) - ), - pull( - pull.values([msg.slice(1)]), - lp.decode() - ) - ]), - pull.collect((err, data) => { - if (err) { return cb(err) } - cb(null, data) - }) - ) -} diff --git a/test/mplex.spec.js b/test/mplex.spec.js deleted file mode 100644 index 88674fb..0000000 --- a/test/mplex.spec.js +++ /dev/null @@ -1,82 +0,0 @@ -/* eslint-env mocha */ -/* eslint max-nested-callbacks: ["error", 5] */ -'use strict' - -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) - -const pull = require('pull-stream') -const pair = require('pull-pair/duplex') -const pushable = require('pull-pushable') -const abortable = require('pull-abortable') - -const Mplex = require('../src') -const utils = require('../src/utils') -const consts = require('../src/consts') - -const series = require('async/series') - -describe('channel', () => { - it('should be writable', (done) => { - const plex = new Mplex(false) - - plex.on('stream', (stream) => { - pull(pull.values([Buffer.from('hellooooooooooooo')]), stream) - }) - - utils.encodeMsg(3, - consts.type.NEW, - Buffer.from('chan1'), - (err, msg) => { - expect(err).to.not.exist() - pull( - pull.values([msg]), - plex, - pull.drain((_data) => { - expect(err).to.not.exist() - utils.decodeMsg(_data, (err, data) => { - expect(err).to.not.exist() - const { id, type } = data[0] - expect(id).to.eql(3) - expect(type).to.eql(consts.type.IN_MESSAGE) - expect(data[1]).to.deep.eql(Buffer.from('hellooooooooooooo')) - done() - }) - }) - ) - }) - }) - - it('should be readable', (done) => { - const plex = new Mplex(true) - - plex.on('stream', (stream) => { - pull( - stream, - // drain, because otherwise we have to send an explicit close - pull.drain((data) => { - expect(data).to.deep.eql(Buffer.from('hellooooooooooooo')) - done() - }) - ) - }) - - series([ - (cb) => utils.encodeMsg(3, - consts.type.NEW, - Buffer.from('chan1'), cb), - (cb) => utils.encodeMsg(3, - consts.type.IN_MESSAGE, - Buffer.from('hellooooooooooooo'), - cb) - ], (err, msgs) => { - expect(err).to.not.exist() - pull( - pull.values(msgs), - plex - ) - }) - }) -})