From 9b46588686ba33385023be61cae0c0e88ccb73a1 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Mon, 16 Mar 2020 12:21:39 +0000 Subject: [PATCH] fix: dont rely in node globals This PR removes the dependency on node globals, so the users don't need to rely on browser bundlers magic. related to https://github.com/ipfs/js-ipfs/issues/2924 --- BufferList.js | 1 + bl.js | 4 ++-- package.json | 2 ++ test/convert.js | 2 +- test/indexOf.js | 2 +- test/isBufferList.js | 2 +- test/test.js | 2 +- 7 files changed, 9 insertions(+), 6 deletions(-) diff --git a/BufferList.js b/BufferList.js index ea96d28..6dad448 100644 --- a/BufferList.js +++ b/BufferList.js @@ -1,5 +1,6 @@ 'use strict' +const { Buffer } = require('buffer') const symbol = Symbol.for('BufferList') function BufferList (buf) { diff --git a/bl.js b/bl.js index ad6a170..40228f8 100644 --- a/bl.js +++ b/bl.js @@ -1,7 +1,7 @@ 'use strict' const DuplexStream = require('readable-stream').Duplex -const util = require('util') +const inherits = require('inherits') const BufferList = require('./BufferList') function BufferListStream (callback) { @@ -33,7 +33,7 @@ function BufferListStream (callback) { DuplexStream.call(this) } -util.inherits(BufferListStream, DuplexStream) +inherits(BufferListStream, DuplexStream) Object.assign(BufferListStream.prototype, BufferList.prototype) BufferListStream.prototype._new = function _new (callback) { diff --git a/package.json b/package.json index 91f6e4d..bd73b33 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,8 @@ ], "license": "MIT", "dependencies": { + "buffer": "^5.5.0", + "inherits": "^2.0.4", "readable-stream": "^3.4.0" }, "devDependencies": { diff --git a/test/convert.js b/test/convert.js index 9ab1566..9f3e235 100644 --- a/test/convert.js +++ b/test/convert.js @@ -2,7 +2,7 @@ const tape = require('tape') const { BufferList, BufferListStream } = require('../') -const { Buffer } = require('safe-buffer') +const { Buffer } = require('buffer') tape('convert from BufferList to BufferListStream', (t) => { const data = Buffer.from(`TEST-${Date.now()}`) diff --git a/test/indexOf.js b/test/indexOf.js index d675d1a..62dcb01 100644 --- a/test/indexOf.js +++ b/test/indexOf.js @@ -2,7 +2,7 @@ const tape = require('tape') const BufferList = require('../') -const Buffer = require('safe-buffer').Buffer +const { Buffer } = require('buffer') tape('indexOf single byte needle', (t) => { const bl = new BufferList(['abcdefg', 'abcdefg', '12345']) diff --git a/test/isBufferList.js b/test/isBufferList.js index f656173..9d895d5 100644 --- a/test/isBufferList.js +++ b/test/isBufferList.js @@ -2,7 +2,7 @@ const tape = require('tape') const { BufferList, BufferListStream } = require('../') -const { Buffer } = require('safe-buffer') +const { Buffer } = require('buffer') tape('isBufferList positives', (t) => { t.ok(BufferList.isBufferList(new BufferList())) diff --git a/test/test.js b/test/test.js index 3e51da3..cb1f257 100644 --- a/test/test.js +++ b/test/test.js @@ -5,7 +5,7 @@ const crypto = require('crypto') const fs = require('fs') const path = require('path') const BufferList = require('../') -const Buffer = require('safe-buffer').Buffer +const { Buffer } = require('buffer') const encodings = ('hex utf8 utf-8 ascii binary base64' +