From 8dfc9b5f273a0e4b9004f404ef78c5e793ff9726 Mon Sep 17 00:00:00 2001 From: Marius Darila Date: Mon, 17 Oct 2016 17:14:59 +0300 Subject: [PATCH] fix(ipfs): prevent stringify on stream --- src/IpfsApiHelper.ts | 4 ++-- src/IpfsConnector.ts | 4 +++- tests/index.js | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/IpfsApiHelper.ts b/src/IpfsApiHelper.ts index fbdd10c..de71c54 100644 --- a/src/IpfsApiHelper.ts +++ b/src/IpfsApiHelper.ts @@ -40,9 +40,9 @@ export class IpfsApiHelper { * @param isProtobuf * @returns {any} */ - add(data: Object | Buffer, isProtobuf = false) { + add(data: any, isProtobuf = false) { let dataBuffer: Buffer; - if (Buffer.isBuffer(data)) { + if (Buffer.isBuffer(data) || isProtobuf) { dataBuffer = data; } else { dataBuffer = toDataBuffer(data); diff --git a/src/IpfsConnector.ts b/src/IpfsConnector.ts index 7535cd4..8f507d2 100644 --- a/src/IpfsConnector.ts +++ b/src/IpfsConnector.ts @@ -52,7 +52,9 @@ export class IpfsConnector extends EventEmitter { return this.emit(events.SERVICE_STARTED); } if (data.includes('API server')) { - this.options.apiAddress = data.toString().trim().split(' ').pop(); + setTimeout(() => { + this.options.apiAddress = data.toString().trim().split(' ').pop(); + }, 1); } }); this._callbacks.set('ipfs.exit', (code: number, signal: string) => { diff --git a/tests/index.js b/tests/index.js index d94091a..34bb8c4 100644 --- a/tests/index.js +++ b/tests/index.js @@ -38,6 +38,7 @@ describe('IpfsConnector', function () { it('should set a different logger', function () { instance.setLogger(logger); expect(instance.logger).to.deep.equal(logger); + instance.setLogger(console); }); it('should emit error when specifying bad ipfs-api address', function (done) { const memAddr = instance.options.apiAddress; @@ -110,6 +111,7 @@ describe('IpfsConnector', function () { }); instance.setPorts({ api: 5041, swarm: 4041, gateway: 8040 }, true) .then((ports) => { + console.log(instance.options); expect(instance.options.apiAddress).to.equal('/ip4/127.0.0.1/tcp/5041'); expect(ports).to.exist; })