From 501ae1db050b964169d3b4c9c3460fd60625d3f4 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 30 Jul 2020 16:58:14 +0100 Subject: [PATCH 1/3] fix: swap node buffers for uint8arrays Upgrades all the datastores to get/put `Uint8Array`s instead of node `Buffer`s. BREAKING CHANGES: - Swaps out node `Buffer`s for `Uint8Array`s --- README.md | 12 ++++++------ package.json | 17 ++++++++--------- src/api-addr.js | 4 ++-- src/config.js | 11 ++++++----- src/index.js | 2 +- src/spec.js | 9 +++++---- src/version.js | 7 ++++--- test/api-addr-test.js | 4 ++-- test/blockstore-test.js | 34 +++++++++++++++++----------------- test/config-test.js | 3 +-- test/datastore-test.js | 6 +++--- test/pins-test.js | 6 +++--- test/stat-test.js | 3 ++- 13 files changed, 60 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index d44bdd3d..b194ec73 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,8 @@ This is the implementation of the [IPFS repo spec](https://github.com/ipfs/specs - [`Promise repo.exists()`](#promiseboolean-repoexists) - [`Promise repo.isInitialized()`](#promiseboolean-repoisinitialized) - [Repos](#repos) - - [`Promise repo.put(key, value:Buffer)`](#promise-repoputkey-valuebuffer) - - [`Promise repo.get(key)`](#promisebuffer-repogetkey) + - [`Promise repo.put(key, value:Uint8Array)`](#promise-repoputkey-valueuint8array) + - [`Promise repo.get(key)`](#promiseuint8array-repogetkey) - [Blocks](#blocks) - [`Promise repo.blocks.put(block:Block)`](#promiseblock-repoblocksputblockblock) - [`AsyncIterator repo.blocks.putMany(source:AsyncIterable)`](#asynciteratorblock-repoblocksputmanysourceasynciterableblock) @@ -214,17 +214,17 @@ The returned promise resolves to `false` if the repo has not been initialized an Root repo: -#### `Promise repo.put(key, value:Buffer)` +#### `Promise repo.put(key, value:Uint8Array)` Put a value at the root of the repo -* `key` can be a buffer, a string or a [Key][] +* `key` can be a Uint8Array, a string or a [Key][] -#### `Promise repo.get(key)` +#### `Promise repo.get(key)` Get a value at the root of the repo -* `key` can be a buffer, a string or a [Key][] +* `key` can be a Uint8Array, a string or a [Key][] ### Blocks diff --git a/package.json b/package.json index a1c976df..57684a43 100644 --- a/package.json +++ b/package.json @@ -59,23 +59,22 @@ }, "dependencies": { "bignumber.js": "^9.0.0", - "buffer": "^5.6.0", "bytes": "^3.1.0", - "cids": "^0.8.0", - "datastore-core": "^1.1.0", - "datastore-fs": "^1.1.0", - "datastore-level": "^1.1.0", + "cids": "multiformats/js-cid#fix/support-uint8arrays", + "datastore-core": "^2.0.0", + "datastore-fs": "^2.0.0", + "datastore-level": "^2.0.0", "debug": "^4.1.0", "err-code": "^2.0.0", - "interface-datastore": "^1.0.2", + "interface-datastore": "^2.0.0", "ipfs-repo-migrations": "^2.0.0", - "ipfs-utils": "^2.2.0", - "ipld-block": "^0.9.1", + "ipfs-utils": "ipfs/js-ipfs-utils#feat/add-utility-uint8array-functions", + "ipld-block": "^0.9.2", "it-map": "^1.0.2", "it-pushable": "^1.4.0", "just-safe-get": "^2.0.0", "just-safe-set": "^2.1.0", - "multibase": "^1.0.1", + "multibase": "^2.0.0", "p-queue": "^6.0.0", "proper-lockfile": "^4.0.0", "sort-keys": "^4.0.0" diff --git a/src/api-addr.js b/src/api-addr.js index c1a7fc57..95204eb4 100644 --- a/src/api-addr.js +++ b/src/api-addr.js @@ -1,7 +1,7 @@ 'use strict' -const { Buffer } = require('buffer') const Key = require('interface-datastore').Key +const uint8ArrayFromString = require('ipfs-utils/src/uint8arrays/from-string') const apiFile = new Key('api') @@ -23,7 +23,7 @@ module.exports = (store) => { * @returns {Promise} */ async set (value) { // eslint-disable-line require-await - return store.put(apiFile, Buffer.from(value.toString())) + return store.put(apiFile, uint8ArrayFromString(value.toString())) }, /** * Deletes api file diff --git a/src/config.js b/src/config.js index 35b17dc7..17851ad3 100644 --- a/src/config.js +++ b/src/config.js @@ -1,12 +1,13 @@ 'use strict' -const { Buffer } = require('buffer') const Key = require('interface-datastore').Key const { default: Queue } = require('p-queue') const _get = require('just-safe-get') const _set = require('just-safe-set') const errcode = require('err-code') const errors = require('./errors') +const uint8ArrayToString = require('ipfs-utils/src/uint8arrays/to-string') +const uint8ArrayFromString = require('ipfs-utils/src/uint8arrays/from-string') const configKey = new Key('config') @@ -44,7 +45,7 @@ module.exports = (store) => { return } - const config = JSON.parse(encodedValue.toString()) + const config = JSON.parse(uint8ArrayToString(encodedValue)) if (key !== undefined && _get(config, key) === undefined) { throw new errors.NotFoundError(`Key ${key} does not exist in config`) } @@ -70,7 +71,7 @@ module.exports = (store) => { throw errcode(new Error('Invalid key type: ' + typeof key), 'ERR_INVALID_KEY') } - if (value === undefined || Buffer.isBuffer(value)) { + if (value === undefined || (value instanceof Uint8Array)) { throw errcode(new Error('Invalid value type: ' + typeof value), 'ERR_INVALID_VALUE') } @@ -89,7 +90,7 @@ module.exports = (store) => { * @returns {void} */ async replace (value, options = {}) { // eslint-disable-line require-await - if (!value || Buffer.isBuffer(value)) { + if (!value || (value instanceof Uint8Array)) { throw errcode(new Error('Invalid value type: ' + typeof value), 'ERR_INVALID_VALUE') } @@ -127,7 +128,7 @@ module.exports = (store) => { } function _saveAll (config) { - const buf = Buffer.from(JSON.stringify(config, null, 2)) + const buf = uint8ArrayFromString(JSON.stringify(config, null, 2)) return store.put(configKey, buf) } } diff --git a/src/index.js b/src/index.js index 8262045a..33c8598b 100644 --- a/src/index.js +++ b/src/index.js @@ -369,7 +369,7 @@ async function getSize (queryFn) { const sum = new Big(0) for await (const block of queryFn.query({})) { sum.plus(block.value.byteLength) - .plus(block.key.toBuffer().byteLength) + .plus(block.key.uint8Array().byteLength) } return sum } diff --git a/src/spec.js b/src/spec.js index cc839065..c6980659 100644 --- a/src/spec.js +++ b/src/spec.js @@ -1,8 +1,9 @@ 'use strict' -const { Buffer } = require('buffer') const Key = require('interface-datastore').Key const sortKeys = require('sort-keys') +const uint8ArrayToString = require('ipfs-utils/src/uint8arrays/to-string') +const uint8ArrayFromString = require('ipfs-utils/src/uint8arrays/from-string') const specKey = new Key('datastore_spec') @@ -19,11 +20,11 @@ module.exports = (store) => { /** * Get the current datastore spec. * - * @returns {Promise} + * @returns {Promise} */ async get () { const buf = await store.get(specKey) - return JSON.parse(buf.toString()) + return JSON.parse(uint8ArrayToString(buf)) }, /** * Set the datastore spec of the repo, writing it to the underlying store. @@ -32,7 +33,7 @@ module.exports = (store) => { * @returns {Promise} */ async set (spec) { // eslint-disable-line require-await - return store.put(specKey, Buffer.from(JSON.stringify(sortKeys(spec, { deep: true })))) + return store.put(specKey, uint8ArrayFromString(JSON.stringify(sortKeys(spec, { deep: true })))) } } } diff --git a/src/version.js b/src/version.js index 0241f937..e7e17590 100644 --- a/src/version.js +++ b/src/version.js @@ -1,9 +1,10 @@ 'use strict' -const { Buffer } = require('buffer') const Key = require('interface-datastore').Key const debug = require('debug') const log = debug('ipfs:repo:version') +const uint8ArrayToString = require('ipfs-utils/src/uint8arrays/to-string') +const uint8ArrayFromString = require('ipfs-utils/src/uint8arrays/from-string') const versionKey = new Key('version') @@ -24,7 +25,7 @@ module.exports = (store) => { */ async get () { const buf = await store.get(versionKey) - return parseInt(buf.toString().trim(), 10) + return parseInt(uint8ArrayToString(buf), 10) }, /** * Set the version of the repo, writing it to the underlying store. @@ -33,7 +34,7 @@ module.exports = (store) => { * @returns {Promise} */ async set (version) { // eslint-disable-line require-await - return store.put(versionKey, Buffer.from(String(version))) + return store.put(versionKey, uint8ArrayFromString(String(version))) }, /** * Check the current version, and returns true if versions matches diff --git a/test/api-addr-test.js b/test/api-addr-test.js index 4f0657b4..d487ac25 100644 --- a/test/api-addr-test.js +++ b/test/api-addr-test.js @@ -1,9 +1,9 @@ /* eslint-env mocha */ 'use strict' -const { Buffer } = require('buffer') const { expect } = require('./utils/chai') const apiAddr = require('../src/api-addr') +const uint8ArrayFromString = require('ipfs-utils/src/uint8arrays/from-string') module.exports = () => { describe('api-addr', () => { @@ -31,7 +31,7 @@ module.exports = () => { await api.set('0') - expect(val).to.deep.equal(Buffer.from('0')) + expect(val).to.deep.equal(uint8ArrayFromString('0')) }) }) }) diff --git a/test/blockstore-test.js b/test/blockstore-test.js index a899951c..0da448b7 100644 --- a/test/blockstore-test.js +++ b/test/blockstore-test.js @@ -2,7 +2,6 @@ /* eslint-env mocha */ 'use strict' -const { Buffer } = require('buffer') const { expect } = require('./utils/chai') const Block = require('ipld-block') const CID = require('cids') @@ -14,9 +13,10 @@ const IPFSRepo = require('../') const drain = require('it-drain') const all = require('it-all') const first = require('it-first') +const uint8ArrayFromString = require('ipfs-utils/src/uint8arrays/from-string') async function makeBlock () { - const bData = Buffer.from(`hello-${Math.random()}`) + const bData = uint8ArrayFromString(`hello-${Math.random()}`) const hash = await multihashing(bData, 'sha2-256') return new Block(bData, new CID(hash)) @@ -24,8 +24,8 @@ async function makeBlock () { module.exports = (repo) => { describe('blockstore', () => { - const blockData = range(100).map((i) => Buffer.from(`hello-${i}-${Math.random()}`)) - const bData = Buffer.from('hello world') + const blockData = range(100).map((i) => uint8ArrayFromString(`hello-${i}-${Math.random()}`)) + const bData = uint8ArrayFromString('hello world') let b before(async () => { @@ -51,7 +51,7 @@ module.exports = (repo) => { }) it('empty value', async () => { - const d = Buffer.alloc(0) + const d = new Uint8Array(0) const multihash = await multihashing(d, 'sha2-256') const empty = new Block(d, new CID(multihash)) await repo.blocks.put(empty) @@ -69,7 +69,7 @@ module.exports = (repo) => { it('.putMany', async function () { this.timeout(15000) // add time for ci const blocks = await Promise.all(range(50).map(async (i) => { - const d = Buffer.from('many' + Math.random()) + const d = uint8ArrayFromString('many' + Math.random()) const hash = await multihashing(d, 'sha2-256') return new Block(d, new CID(hash)) })) @@ -117,7 +117,7 @@ module.exports = (repo) => { }) it('should get block stored under v0 CID with a v1 CID', async () => { - const data = Buffer.from(`TEST${Date.now()}`) + const data = uint8ArrayFromString(`TEST${Date.now()}`) const hash = await multihashing(data, 'sha2-256') const cid = new CID(hash) await repo.blocks.put(new Block(data, cid)) @@ -126,7 +126,7 @@ module.exports = (repo) => { }) it('should get block stored under v1 CID with a v0 CID', async () => { - const data = Buffer.from(`TEST${Date.now()}`) + const data = uint8ArrayFromString(`TEST${Date.now()}`) const hash = await multihashing(data, 'sha2-256') const cid = new CID(1, 'dag-pb', hash) @@ -140,7 +140,7 @@ module.exports = (repo) => { }) it('throws ERR_NOT_FOUND when requesting non-dag-pb CID that is not in the store', async () => { - const data = Buffer.from(`TEST${Date.now()}`) + const data = uint8ArrayFromString(`TEST${Date.now()}`) const hash = await multihashing(data, 'sha2-256') const cid = new CID(1, 'dag-cbor', hash) @@ -149,7 +149,7 @@ module.exports = (repo) => { it('throws unknown error encountered when getting a block', async () => { const err = new Error('wat') - const data = Buffer.from(`TEST${Date.now()}`) + const data = uint8ArrayFromString(`TEST${Date.now()}`) const hash = await multihashing(data, 'sha2-256') const cid = new CID(hash) const key = cidToKey(cid) @@ -228,7 +228,7 @@ module.exports = (repo) => { }) it('should get block stored under v0 CID with a v1 CID', async () => { - const data = Buffer.from(`TEST${Date.now()}`) + const data = uint8ArrayFromString(`TEST${Date.now()}`) const hash = await multihashing(data, 'sha2-256') const cid = new CID(hash) await repo.blocks.put(new Block(data, cid)) @@ -237,7 +237,7 @@ module.exports = (repo) => { }) it('should get block stored under v1 CID with a v0 CID', async () => { - const data = Buffer.from(`TEST${Date.now()}`) + const data = uint8ArrayFromString(`TEST${Date.now()}`) const hash = await multihashing(data, 'sha2-256') const cid = new CID(1, 'dag-pb', hash) @@ -251,7 +251,7 @@ module.exports = (repo) => { }) it('throws ERR_NOT_FOUND when requesting non-dag-pb CID that is not in the store', async () => { - const data = Buffer.from(`TEST${Date.now()}`) + const data = uint8ArrayFromString(`TEST${Date.now()}`) const hash = await multihashing(data, 'sha2-256') const cid = new CID(1, 'dag-cbor', hash) @@ -260,7 +260,7 @@ module.exports = (repo) => { it('throws unknown error encountered when getting a block', async () => { const err = new Error('wat') - const data = Buffer.from(`TEST${Date.now()}`) + const data = uint8ArrayFromString(`TEST${Date.now()}`) const hash = await multihashing(data, 'sha2-256') const cid = new CID(hash) const key = cidToKey(cid) @@ -317,7 +317,7 @@ module.exports = (repo) => { }) it('should have block stored under v0 CID with a v1 CID', async () => { - const data = Buffer.from(`TEST${Date.now()}`) + const data = uint8ArrayFromString(`TEST${Date.now()}`) const hash = await multihashing(data, 'sha2-256') const cid = new CID(hash) await repo.blocks.put(new Block(data, cid)) @@ -326,7 +326,7 @@ module.exports = (repo) => { }) it('should have block stored under v1 CID with a v0 CID', async () => { - const data = Buffer.from(`TEST${Date.now()}`) + const data = uint8ArrayFromString(`TEST${Date.now()}`) const hash = await multihashing(data, 'sha2-256') const cid = new CID(1, 'dag-pb', hash) @@ -340,7 +340,7 @@ module.exports = (repo) => { }) it('returns false when requesting non-dag-pb CID that is not in the store', async () => { - const data = Buffer.from(`TEST${Date.now()}`) + const data = uint8ArrayFromString(`TEST${Date.now()}`) const hash = await multihashing(data, 'sha2-256') const cid = new CID(1, 'dag-cbor', hash) const result = await repo.blocks.has(cid) diff --git a/test/config-test.js b/test/config-test.js index 369eee9c..27e29ba9 100644 --- a/test/config-test.js +++ b/test/config-test.js @@ -1,7 +1,6 @@ /* eslint-env mocha */ 'use strict' -const { Buffer } = require('buffer') const { expect } = require('./utils/chai') module.exports = (repo) => { @@ -12,7 +11,7 @@ module.exports = (repo) => { }) it('should throw when invalid value is passed', () => { - return expect(repo.config.set('foo', Buffer.from([0, 1, 2]))).to.eventually.be.rejected().with.property('code', 'ERR_INVALID_VALUE') + return expect(repo.config.set('foo', Uint8Array.from([0, 1, 2]))).to.eventually.be.rejected().with.property('code', 'ERR_INVALID_VALUE') }) }) describe('.get', () => { diff --git a/test/datastore-test.js b/test/datastore-test.js index dc42019d..420c5e82 100644 --- a/test/datastore-test.js +++ b/test/datastore-test.js @@ -2,15 +2,15 @@ /* eslint-env mocha */ 'use strict' -const { Buffer } = require('buffer') const { expect } = require('./utils/chai') const range = require('just-range') const Key = require('interface-datastore').Key +const uint8ArrayFromString = require('ipfs-utils/src/uint8arrays/from-string') module.exports = (repo) => { describe('datastore', () => { - const dataList = range(100).map((i) => Buffer.from(`hello-${i}-${Math.random()}`)) - const data = Buffer.from('hello world') + const dataList = range(100).map((i) => uint8ArrayFromString(`hello-${i}-${Math.random()}`)) + const data = uint8ArrayFromString('hello world') const b = new Key('hello') describe('.put', () => { diff --git a/test/pins-test.js b/test/pins-test.js index d0c12c04..5958b190 100644 --- a/test/pins-test.js +++ b/test/pins-test.js @@ -2,15 +2,15 @@ /* eslint-env mocha */ 'use strict' -const { Buffer } = require('buffer') const { expect } = require('./utils/chai') const range = require('just-range') const Key = require('interface-datastore').Key +const uint8ArrayFromString = require('ipfs-utils/src/uint8arrays/from-string') module.exports = (repo) => { describe('pins', () => { - const dataList = range(100).map((i) => Buffer.from(`hello-${i}-${Math.random()}`)) - const data = Buffer.from('hello world') + const dataList = range(100).map((i) => uint8ArrayFromString(`hello-${i}-${Math.random()}`)) + const data = uint8ArrayFromString('hello world') const b = new Key('hello') it('exists', () => { diff --git a/test/stat-test.js b/test/stat-test.js index a62fe48b..32d57d6c 100644 --- a/test/stat-test.js +++ b/test/stat-test.js @@ -4,12 +4,13 @@ const { expect } = require('./utils/chai') const Block = require('ipld-block') const CID = require('cids') +const uint8ArrayFromString = require('ipfs-utils/src/uint8arrays/from-string') module.exports = (repo) => { describe('stat', () => { before(async () => { const data = new Block( - Buffer.from('foo'), + uint8ArrayFromString('foo'), new CID('bafyreighz6vdlkdsvp4nu3lxhsofnk2eqxn6o57ag3mfxkqa7c327djhra') ) await repo.blocks.put(data) From 15818e5b8be33edf89acfef70895db94f5e425e2 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 5 Aug 2020 07:53:19 +0100 Subject: [PATCH 2/3] chore: remove gh dep versions --- package.json | 12 ++++++------ src/api-addr.js | 2 +- src/blockstore-utils.js | 3 ++- src/config.js | 4 ++-- src/index.js | 2 +- src/spec.js | 4 ++-- src/version.js | 4 ++-- test/api-addr-test.js | 2 +- test/blockstore-test.js | 7 ++++--- test/datastore-test.js | 2 +- test/interop-test.js | 5 +++-- test/pins-test.js | 2 +- test/stat-test.js | 2 +- 13 files changed, 27 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 57684a43..3e94b12f 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "it-first": "^1.0.2", "just-range": "^2.1.0", "memdown": "^5.1.0", - "multihashing-async": "^1.0.0", + "multihashing-async": "^2.0.0", "ncp": "^2.0.0", "rimraf": "^3.0.0", "sinon": "^9.0.2" @@ -60,21 +60,21 @@ "dependencies": { "bignumber.js": "^9.0.0", "bytes": "^3.1.0", - "cids": "multiformats/js-cid#fix/support-uint8arrays", + "cids": "^1.0.0", "datastore-core": "^2.0.0", "datastore-fs": "^2.0.0", "datastore-level": "^2.0.0", "debug": "^4.1.0", "err-code": "^2.0.0", "interface-datastore": "^2.0.0", - "ipfs-repo-migrations": "^2.0.0", - "ipfs-utils": "ipfs/js-ipfs-utils#feat/add-utility-uint8array-functions", - "ipld-block": "^0.9.2", + "ipfs-repo-migrations": "^3.0.0", + "ipfs-utils": "^2.3.1", + "ipld-block": "^0.10.0", "it-map": "^1.0.2", "it-pushable": "^1.4.0", "just-safe-get": "^2.0.0", "just-safe-set": "^2.1.0", - "multibase": "^2.0.0", + "multibase": "^3.0.0", "p-queue": "^6.0.0", "proper-lockfile": "^4.0.0", "sort-keys": "^4.0.0" diff --git a/src/api-addr.js b/src/api-addr.js index 95204eb4..4fac4504 100644 --- a/src/api-addr.js +++ b/src/api-addr.js @@ -1,7 +1,7 @@ 'use strict' const Key = require('interface-datastore').Key -const uint8ArrayFromString = require('ipfs-utils/src/uint8arrays/from-string') +const uint8ArrayFromString = require('uint8arrays/from-string') const apiFile = new Key('api') diff --git a/src/blockstore-utils.js b/src/blockstore-utils.js index fece2f98..22b9ba2f 100644 --- a/src/blockstore-utils.js +++ b/src/blockstore-utils.js @@ -4,6 +4,7 @@ const { Key } = require('interface-datastore') const CID = require('cids') const multibase = require('multibase') const errcode = require('err-code') +const uint8ArrayToString = require('uint8arrays/to-string') /** * Transform a cid to the appropriate datastore key. @@ -16,7 +17,7 @@ exports.cidToKey = cid => { throw errcode(new Error('Not a valid cid'), 'ERR_INVALID_CID') } - return new Key('/' + multibase.encode('base32', cid.multihash).toString().slice(1).toUpperCase(), false) + return new Key('/' + uint8ArrayToString(multibase.encode('base32', cid.multihash)).slice(1).toUpperCase(), false) } /** diff --git a/src/config.js b/src/config.js index 17851ad3..149af8a0 100644 --- a/src/config.js +++ b/src/config.js @@ -6,8 +6,8 @@ const _get = require('just-safe-get') const _set = require('just-safe-set') const errcode = require('err-code') const errors = require('./errors') -const uint8ArrayToString = require('ipfs-utils/src/uint8arrays/to-string') -const uint8ArrayFromString = require('ipfs-utils/src/uint8arrays/from-string') +const uint8ArrayToString = require('uint8arrays/to-string') +const uint8ArrayFromString = require('uint8arrays/from-string') const configKey = new Key('config') diff --git a/src/index.js b/src/index.js index 33c8598b..4ee18545 100644 --- a/src/index.js +++ b/src/index.js @@ -358,7 +358,7 @@ class IpfsRepo { count = count.plus(1) size = size .plus(block.data.byteLength) - .plus(block.cid.buffer.byteLength) + .plus(block.cid.bytes.byteLength) } return { count, size } diff --git a/src/spec.js b/src/spec.js index c6980659..1605d344 100644 --- a/src/spec.js +++ b/src/spec.js @@ -2,8 +2,8 @@ const Key = require('interface-datastore').Key const sortKeys = require('sort-keys') -const uint8ArrayToString = require('ipfs-utils/src/uint8arrays/to-string') -const uint8ArrayFromString = require('ipfs-utils/src/uint8arrays/from-string') +const uint8ArrayToString = require('uint8arrays/to-string') +const uint8ArrayFromString = require('uint8arrays/from-string') const specKey = new Key('datastore_spec') diff --git a/src/version.js b/src/version.js index e7e17590..18b42a7a 100644 --- a/src/version.js +++ b/src/version.js @@ -3,8 +3,8 @@ const Key = require('interface-datastore').Key const debug = require('debug') const log = debug('ipfs:repo:version') -const uint8ArrayToString = require('ipfs-utils/src/uint8arrays/to-string') -const uint8ArrayFromString = require('ipfs-utils/src/uint8arrays/from-string') +const uint8ArrayToString = require('uint8arrays/to-string') +const uint8ArrayFromString = require('uint8arrays/from-string') const versionKey = new Key('version') diff --git a/test/api-addr-test.js b/test/api-addr-test.js index d487ac25..d6a519da 100644 --- a/test/api-addr-test.js +++ b/test/api-addr-test.js @@ -3,7 +3,7 @@ const { expect } = require('./utils/chai') const apiAddr = require('../src/api-addr') -const uint8ArrayFromString = require('ipfs-utils/src/uint8arrays/from-string') +const uint8ArrayFromString = require('uint8arrays/from-string') module.exports = () => { describe('api-addr', () => { diff --git a/test/blockstore-test.js b/test/blockstore-test.js index 0da448b7..e6197a97 100644 --- a/test/blockstore-test.js +++ b/test/blockstore-test.js @@ -13,7 +13,8 @@ const IPFSRepo = require('../') const drain = require('it-drain') const all = require('it-all') const first = require('it-first') -const uint8ArrayFromString = require('ipfs-utils/src/uint8arrays/from-string') +const uint8ArrayFromString = require('uint8arrays/from-string') +const uint8ArrayToString = require('uint8arrays/to-string') async function makeBlock () { const bData = uint8ArrayFromString(`hello-${Math.random()}`) @@ -387,7 +388,7 @@ module.exports = (repo) => { it('returns key/values for block data', async () => { const blocks = await all(repo.blocks.query({})) - const block = blocks.find(block => block.data.toString('base64') === block1.data.toString('base64')) + const block = blocks.find(block => uint8ArrayToString(block.data, 'base64') === uint8ArrayToString(block1.data, 'base64')) expect(block).to.be.ok() expect(block.cid.multihash).to.deep.equal(block1.cid.multihash) @@ -398,7 +399,7 @@ module.exports = (repo) => { const blocksWithPrefix = await all(repo.blocks.query({ prefix: cidToKey(block1.cid).toString().substring(0, 10) })) - const block = blocksWithPrefix.find(block => block.data.toString('base64') === block1.data.toString('base64')) + const block = blocksWithPrefix.find(block => uint8ArrayToString(block.data, 'base64') === uint8ArrayToString(block1.data, 'base64')) expect(block).to.be.ok() expect(block.cid.multihash).to.deep.equal(block1.cid.multihash) diff --git a/test/datastore-test.js b/test/datastore-test.js index 420c5e82..613d1982 100644 --- a/test/datastore-test.js +++ b/test/datastore-test.js @@ -5,7 +5,7 @@ const { expect } = require('./utils/chai') const range = require('just-range') const Key = require('interface-datastore').Key -const uint8ArrayFromString = require('ipfs-utils/src/uint8arrays/from-string') +const uint8ArrayFromString = require('uint8arrays/from-string') module.exports = (repo) => { describe('datastore', () => { diff --git a/test/interop-test.js b/test/interop-test.js index 469408b0..2e7c6697 100644 --- a/test/interop-test.js +++ b/test/interop-test.js @@ -5,6 +5,7 @@ const { expect } = require('./utils/chai') const mh = require('multihashing-async').multihash const CID = require('cids') const Key = require('interface-datastore').Key +const uint8ArrayToString = require('uint8arrays/to-string') module.exports = (repo) => { describe('interop', () => { @@ -14,7 +15,7 @@ module.exports = (repo) => { ) const val = await repo.blocks.get(new CID(welcomeHash)) - expect(val.data.toString()).to.match(/Hello and Welcome to IPFS/) + expect(uint8ArrayToString(val.data)).to.match(/Hello and Welcome to IPFS/) }) it('reads a bunch of blocks', async () => { @@ -35,7 +36,7 @@ module.exports = (repo) => { it('reads DHT records from the datastore', async () => { const val = await repo.datastore.get(new Key('/AHE5I5B7TY')) - expect(val.toString('hex')).to.eql('0a0601c9d4743f9e12097465737476616c75651a2212201d22e2a5e140e5cd20d88fc59cd560f4887c7d9acf938ddb24d7207eac40fd2f') + expect(uint8ArrayToString(val, 'base16')).to.eql('0a0601c9d4743f9e12097465737476616c75651a2212201d22e2a5e140e5cd20d88fc59cd560f4887c7d9acf938ddb24d7207eac40fd2f') }) }) } diff --git a/test/pins-test.js b/test/pins-test.js index 5958b190..b203c55f 100644 --- a/test/pins-test.js +++ b/test/pins-test.js @@ -5,7 +5,7 @@ const { expect } = require('./utils/chai') const range = require('just-range') const Key = require('interface-datastore').Key -const uint8ArrayFromString = require('ipfs-utils/src/uint8arrays/from-string') +const uint8ArrayFromString = require('uint8arrays/from-string') module.exports = (repo) => { describe('pins', () => { diff --git a/test/stat-test.js b/test/stat-test.js index 32d57d6c..e10a4ded 100644 --- a/test/stat-test.js +++ b/test/stat-test.js @@ -4,7 +4,7 @@ const { expect } = require('./utils/chai') const Block = require('ipld-block') const CID = require('cids') -const uint8ArrayFromString = require('ipfs-utils/src/uint8arrays/from-string') +const uint8ArrayFromString = require('uint8arrays/from-string') module.exports = (repo) => { describe('stat', () => { From 2e3ddcce1b65082957a2136a813253282e010311 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 5 Aug 2020 07:59:04 +0100 Subject: [PATCH 3/3] chore: add missing dep --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 3e94b12f..5feb0973 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,8 @@ "multibase": "^3.0.0", "p-queue": "^6.0.0", "proper-lockfile": "^4.0.0", - "sort-keys": "^4.0.0" + "sort-keys": "^4.0.0", + "uint8arrays": "^1.0.0" }, "license": "MIT", "contributors": [