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

fix: do not emit empty buffers for non-empty files #225

Merged
merged 1 commit into from
Aug 8, 2018
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
4 changes: 4 additions & 0 deletions src/exporter/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ function streamBytes (dag, node, fileSize, offset, length) {
const file = UnixFS.unmarshal(node.data)

if (!file.data) {
if (file.blockSizes.length) {
return
}

return Buffer.alloc(0)
}

Expand Down
4 changes: 3 additions & 1 deletion test/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ module.exports = (repo) => {
}, done)
})

it('allows multihash hash algorithm to be specified for big file', (done) => {
it('allows multihash hash algorithm to be specified for big file', function (done) {
this.timeout(30000)

eachSeries(testMultihashes, (hashAlg, cb) => {
const options = { hashAlg, strategy: 'flat' }
const content = String(Math.random() + Date.now())
Expand Down
41 changes: 41 additions & 0 deletions test/exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,47 @@ module.exports = (repo) => {
}
], done)
})

it('exports file with data on leaf nodes without emitting empty buffers', function (done) {
this.timeout(30 * 1000)

pull(
pull.values([{
path: '200Bytes.txt',
content: pull.values([bigFile])
}]),
importer(ipld, {
rawLeaves: true
}),
pull.collect(collected)
)

function collected (err, files) {
expect(err).to.not.exist()
expect(files.length).to.equal(1)

pull(
exporter(files[0].multihash, ipld),
pull.collect((err, files) => {
expect(err).to.not.exist()
expect(files.length).to.equal(1)

pull(
files[0].content,
pull.collect((error, buffers) => {
expect(error).to.not.exist()

buffers.forEach(buffer => {
expect(buffer.length).to.not.equal(0)
})

done()
})
)
})
)
}
})
})
}

Expand Down