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

Commit a412253

Browse files
authored
Merge pull request #225 from ipfs/do-not-emit-empty-buffers
fix: do not emit empty buffers for non-empty files
2 parents 877e053 + ccc4ad2 commit a412253

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/exporter/file.js

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ function streamBytes (dag, node, fileSize, offset, length) {
7171
const file = UnixFS.unmarshal(node.data)
7272

7373
if (!file.data) {
74+
if (file.blockSizes.length) {
75+
return
76+
}
77+
7478
return Buffer.alloc(0)
7579
}
7680

test/exporter.js

+41
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,47 @@ module.exports = (repo) => {
760760
}
761761
], done)
762762
})
763+
764+
it('exports file with data on leaf nodes without emitting empty buffers', function (done) {
765+
this.timeout(30 * 1000)
766+
767+
pull(
768+
pull.values([{
769+
path: '200Bytes.txt',
770+
content: pull.values([bigFile])
771+
}]),
772+
importer(ipld, {
773+
rawLeaves: true
774+
}),
775+
pull.collect(collected)
776+
)
777+
778+
function collected (err, files) {
779+
expect(err).to.not.exist()
780+
expect(files.length).to.equal(1)
781+
782+
pull(
783+
exporter(files[0].multihash, ipld),
784+
pull.collect((err, files) => {
785+
expect(err).to.not.exist()
786+
expect(files.length).to.equal(1)
787+
788+
pull(
789+
files[0].content,
790+
pull.collect((error, buffers) => {
791+
expect(error).to.not.exist()
792+
793+
buffers.forEach(buffer => {
794+
expect(buffer.length).to.not.equal(0)
795+
})
796+
797+
done()
798+
})
799+
)
800+
})
801+
)
802+
}
803+
})
763804
})
764805
}
765806

0 commit comments

Comments
 (0)