diff --git a/package.json b/package.json index 41b6cab..62200b9 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ "ipld-in-memory": "^3.0.0", "it-buffer-stream": "^1.0.0", "it-last": "^1.0.0", - "multihashes": "^0.4.14", "nyc": "^15.0.0", "sinon": "^8.0.4" }, diff --git a/src/dag-builder/file/index.js b/src/dag-builder/file/index.js index 0f32c33..f44c5e5 100644 --- a/src/dag-builder/file/index.js +++ b/src/dag-builder/file/index.js @@ -9,6 +9,7 @@ const { } = require('ipld-dag-pb') const all = require('it-all') const parallelBatch = require('it-parallel-batch') +const mc = require('multicodec') const dagBuilders = { flat: require('./flat'), @@ -52,6 +53,23 @@ const reduce = (file, ipld, options) => { if (leaves.length === 1 && leaves[0].single && options.reduceSingleLeafToSelf) { const leaf = leaves[0] + if (leaf.cid.codec === 'raw') { + // only one leaf node which is a buffer + const buffer = await ipld.get(leaf.cid) + + leaf.unixfs = new UnixFS({ + type: 'file', + mtime: file.mtime, + mode: file.mode, + data: buffer + }) + + const node = new DAGNode(leaf.unixfs.marshal()) + + leaf.cid = await ipld.put(node, mc.DAG_PB, options) + leaf.size = node.size + } + return { cid: leaf.cid, path: file.path, diff --git a/src/utils/persist.js b/src/utils/persist.js index 69e5af7..e6970b6 100644 --- a/src/utils/persist.js +++ b/src/utils/persist.js @@ -1,6 +1,6 @@ 'use strict' -const mh = require('multihashes') +const mh = require('multihashing-async').multihash const mc = require('multicodec') const persist = (node, ipld, options) => { diff --git a/test/builder.spec.js b/test/builder.spec.js index bbeb9d0..c9d5522 100644 --- a/test/builder.spec.js +++ b/test/builder.spec.js @@ -4,7 +4,7 @@ const chai = require('chai') chai.use(require('dirty-chai')) const expect = chai.expect -const mh = require('multihashes') +const mh = require('multihashing-async').multihash const IPLD = require('ipld') const inMemory = require('ipld-in-memory') const UnixFS = require('ipfs-unixfs') diff --git a/test/chunker-custom.spec.js b/test/chunker-custom.spec.js index 2dd00f0..8bc80dd 100644 --- a/test/chunker-custom.spec.js +++ b/test/chunker-custom.spec.js @@ -69,5 +69,5 @@ describe('custom chunker', function () { cid: await inmem.put(Buffer.from('hello world'), mc.RAW) } } - it('works with single part', fromPartsTest(single, 11)) + it('works with single part', fromPartsTest(single, 19)) }) diff --git a/test/importer.spec.js b/test/importer.spec.js index cf6784e..0f5b658 100644 --- a/test/importer.spec.js +++ b/test/importer.spec.js @@ -260,7 +260,7 @@ strategies.forEach((strategy) => { type: 'directory' }, '200Bytes.txt with raw leaves': extend({}, baseFiles['200Bytes.txt'], { - cid: 'zb2rhXrz1gkCv8p4nUDZRohY6MzBE9C3HVTVDP72g6Du3SD9Q', + cid: 'QmQmZQxSKQppbsWfVzBvg59Cn3DKtsNVQ94bjAxg2h3Lb8', size: 200 }) }, strategyOverrides[strategy])