diff --git a/package.json b/package.json index f0b29d6..8619680 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ }, "dependencies": { "async": "^2.6.1", - "cids": "~0.5.5", + "cids": "github:ipld/js-cid#refactor/cidv1base32-default", "debug": "^4.1.0", "filereader-stream": "^2.0.0", "hamt-sharding": "~0.0.2", @@ -58,7 +58,7 @@ "ipfs-multipart": "~0.1.0", "ipfs-unixfs": "~0.1.16", "ipfs-unixfs-exporter": "~0.35.5", - "ipfs-unixfs-importer": "~0.38.0", + "ipfs-unixfs-importer": "github:ipfs/js-ipfs-unixfs-importer#refactor/cidv1b32-default", "ipld-dag-pb": "~0.15.0", "is-pull-stream": "~0.0.0", "is-stream": "^1.1.0", diff --git a/src/core/mkdir.js b/src/core/mkdir.js index 555de42..1c5f158 100644 --- a/src/core/mkdir.js +++ b/src/core/mkdir.js @@ -21,7 +21,7 @@ const { const defaultOptions = { parents: false, hashAlg: 'sha2-256', - cidVersion: 0, + cidVersion: 1, shardSplitThreshold: 1000, format: 'dag-pb', flush: true @@ -37,7 +37,7 @@ module.exports = (context) => { options = Object.assign({}, defaultOptions, options) options.parents = options.p || options.parents - options.cidVersion = options.cidVersion || 0 + options.cidVersion = options.cidVersion == null ? 1 : options.cidVersion if (!path) { return callback(new Error('no path given to Mkdir')) diff --git a/src/core/rm.js b/src/core/rm.js index a5288ab..1feb3d1 100644 --- a/src/core/rm.js +++ b/src/core/rm.js @@ -14,7 +14,7 @@ const { const defaultOptions = { recursive: false, - cidVersion: 0, + cidVersion: 1, hashAlg: 'sha2-256', format: 'dag-pb' } diff --git a/src/core/utils/add-link.js b/src/core/utils/add-link.js index ec4f9d8..b9490a6 100644 --- a/src/core/utils/add-link.js +++ b/src/core/utils/add-link.js @@ -21,7 +21,7 @@ const defaultOptions = { name: '', size: undefined, flush: true, - cidVersion: 0, + cidVersion: 1, hashAlg: 'sha2-256', codec: 'dag-pb', shardSplitThreshold: 1000 @@ -111,7 +111,7 @@ const addToDirectory = (context, options, callback) => { (parent, done) => { // Persist the new parent DAGNode context.ipld.put(parent, { - version: options.cidVersion, + version: options.cidVersion == null ? 1 : options.cidVersion, format: options.codec, hashAlg: options.hashAlg, hashOnly: !options.flush diff --git a/src/core/utils/create-node.js b/src/core/utils/create-node.js index c38399d..57bd0fb 100644 --- a/src/core/utils/create-node.js +++ b/src/core/utils/create-node.js @@ -10,7 +10,7 @@ const createNode = (context, type, options, callback) => { waterfall([ (done) => DAGNode.create(new UnixFS(type).marshal(), [], done), (node, done) => context.ipld.put(node, { - version: options.cidVersion, + version: options.cidVersion == null ? 1 : options.cidVersion, format: options.format, hashAlg: options.hashAlg }, (err, cid) => done(err, { diff --git a/src/core/utils/hamt-utils.js b/src/core/utils/hamt-utils.js index de5cdd3..a3c18c9 100644 --- a/src/core/utils/hamt-utils.js +++ b/src/core/utils/hamt-utils.js @@ -24,7 +24,7 @@ const updateHamtDirectory = (context, links, bucket, options, callback) => { (parent, done) => { // Persist the new parent DAGNode context.ipld.put(parent, { - version: options.cidVersion, + version: options.cidVersion == null ? 1 : options.cidVersion, format: options.codec, hashAlg: options.hashAlg, hashOnly: !options.flush diff --git a/src/core/utils/remove-link.js b/src/core/utils/remove-link.js index a4d1240..71fae9e 100644 --- a/src/core/utils/remove-link.js +++ b/src/core/utils/remove-link.js @@ -18,7 +18,7 @@ const defaultOptions = { parentCid: undefined, name: '', flush: true, - cidVersion: 0, + cidVersion: 1, hashAlg: 'sha2-256', codec: 'dag-pb', shardSplitThreshold: 1000 @@ -70,7 +70,7 @@ const removeFromDirectory = (context, options, callback) => { (cb) => DAGNode.rmLink(options.parent, options.name, cb), (newParentNode, cb) => { context.ipld.put(newParentNode, { - version: options.cidVersion, + version: options.cidVersion == null ? 1 : options.cidVersion, format: options.codec, hashAlg: options.hashAlg }, (error, cid) => cb(error, { @@ -131,7 +131,7 @@ const updateShard = (context, positions, child, options, callback) => { (done) => DAGNode.rmLink(node, link.name, done), (node, done) => { context.ipld.put(node, { - version: options.cidVersion, + version: options.cidVersion == null ? 1 : options.cidVersion, format: options.codec, hashAlg: options.hashAlg, hashOnly: !options.flush diff --git a/src/core/write.js b/src/core/write.js index 1b258d3..88ade0d 100644 --- a/src/core/write.js +++ b/src/core/write.js @@ -42,7 +42,7 @@ const defaultOptions = { truncate: false, // whether to truncate the file first rawLeaves: false, reduceSingleLeafToSelf: false, - cidVersion: 0, + cidVersion: 1, hashAlg: 'sha2-256', format: 'dag-pb', parents: false, // whether to create intermediate directories if they do not exist @@ -74,7 +74,7 @@ module.exports = function mfsWrite (context) { options.length = Infinity } - options.cidVersion = options.cidVersion || 0 + options.cidVersion = options.cidVersion == null ? 1 : options.cidVersion waterfall([ (done) => { diff --git a/src/http/mkdir.js b/src/http/mkdir.js index fa4917e..77db6ee 100644 --- a/src/http/mkdir.js +++ b/src/http/mkdir.js @@ -47,7 +47,7 @@ const mfsMkdir = { cidVersion: Joi.number().integer().valid([ 0, 1 - ]).default(0), + ]).default(1), flush: Joi.boolean().default(true) }) .rename('p', 'parents', { diff --git a/src/http/write.js b/src/http/write.js index 0308843..bf5f2f9 100644 --- a/src/http/write.js +++ b/src/http/write.js @@ -77,7 +77,7 @@ const mfsWrite = { cidVersion: Joi.number().integer().valid([ 0, 1 - ]).default(0), + ]).default(1), hashAlg: Joi.string().valid([ 'sha2-256' ]).default('sha2-256'), diff --git a/test/helpers/create-shard.js b/test/helpers/create-shard.js index a195ced..7f54303 100644 --- a/test/helpers/create-shard.js +++ b/test/helpers/create-shard.js @@ -13,7 +13,8 @@ const createShard = (ipld, files, shardSplitThreshold = 10) => { importer(ipld, { shardSplitThreshold, reduceSingleLeafToSelf: false, // same as go-ipfs-mfs implementation, differs from `ipfs add`(!) - leafType: 'raw' // same as go-ipfs-mfs implementation, differs from `ipfs add`(!) + leafType: 'raw', // same as go-ipfs-mfs implementation, differs from `ipfs add`(!) + rawLeaves: false }), collect((err, files) => { if (err) { diff --git a/test/helpers/index.js b/test/helpers/index.js index d817c27..8cfba73 100644 --- a/test/helpers/index.js +++ b/test/helpers/index.js @@ -43,6 +43,6 @@ module.exports = { createTwoShards: require('./create-two-shards'), findTreeWithDepth: require('./find-tree-with-depth'), printTree: require('./print-tree'), - EMPTY_DIRECTORY_HASH: 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn', - EMPTY_DIRECTORY_HASH_BASE32: 'bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354' + EMPTY_DIRECTORY_HASH: 'bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354', + EMPTY_DIRECTORY_HASH_BASE64URL: 'uAXASIFmUhDkGXylhnvQSgMu5Mr5SxW2ZxZZrZeAREjnwmLvv' } diff --git a/test/stat.spec.js b/test/stat.spec.js index 805ac08..aeb3664 100644 --- a/test/stat.spec.js +++ b/test/stat.spec.js @@ -11,7 +11,7 @@ const { createMfs, createShardedDirectory, EMPTY_DIRECTORY_HASH, - EMPTY_DIRECTORY_HASH_BASE32 + EMPTY_DIRECTORY_HASH_BASE64URL } = require('./helpers') describe('stat', () => { @@ -75,18 +75,18 @@ describe('stat', () => { expect(stats.hash).to.equal(EMPTY_DIRECTORY_HASH) }) - it('returns only a base32 hash', async () => { + it('returns only a base64url hash', async () => { const path = `/directory-${Math.random()}` await mfs.mkdir(path) const stats = await mfs.stat(path, { hash: true, - cidBase: 'base32' + cidBase: 'base64url' }) expect(Object.keys(stats).length).to.equal(1) - expect(stats.hash).to.equal(EMPTY_DIRECTORY_HASH_BASE32) + expect(stats.hash).to.equal(EMPTY_DIRECTORY_HASH_BASE64URL) }) it('returns only the size', async () => { @@ -116,7 +116,7 @@ describe('stat', () => { const stats = await mfs.stat(filePath) expect(stats.size).to.equal(smallFile.length) - expect(stats.cumulativeSize).to.equal(71) + expect(stats.cumulativeSize).to.equal(73) expect(stats.blocks).to.equal(1) expect(stats.type).to.equal('file') }) @@ -131,12 +131,12 @@ describe('stat', () => { const stats = await mfs.stat(filePath) expect(stats.size).to.equal(largeFile.length) - expect(stats.cumulativeSize).to.equal(490800) + expect(stats.cumulativeSize).to.equal(490804) expect(stats.blocks).to.equal(2) expect(stats.type).to.equal('file') }) - it('stats a large file with base32', async () => { + it('stats a large file with base64url', async () => { const filePath = '/stat/large-file.txt' await mfs.write(filePath, largeFile, { @@ -145,11 +145,11 @@ describe('stat', () => { }) const stats = await mfs.stat(filePath, { - cidBase: 'base32' + cidBase: 'base64url' }) - expect(stats.hash.startsWith('b')).to.equal(true) + expect(stats.hash.startsWith('u')).to.equal(true) expect(stats.size).to.equal(largeFile.length) - expect(stats.cumulativeSize).to.equal(490800) + expect(stats.cumulativeSize).to.equal(490804) expect(stats.blocks).to.equal(2) expect(stats.type).to.equal('file') })