Skip to content
This repository was archived by the owner on Apr 29, 2020. It is now read-only.

fix: only output unixfs things #49

Merged
merged 1 commit into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
18 changes: 18 additions & 0 deletions src/dag-builder/file/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/persist.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion test/builder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion test/chunker-custom.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
2 changes: 1 addition & 1 deletion test/importer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down