Skip to content

Commit 4c1b9f6

Browse files
committed
fix: handle empty files again
1 parent 57659fc commit 4c1b9f6

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ const fileContent = (cid, node, unixfs, path, resolve, depth, blockstore) => {
137137
length
138138
} = validateOffsetAndLength(fileSize, options.offset, options.length)
139139

140+
if (length === 0) {
141+
return
142+
}
143+
140144
const queue = pushable({
141145
objectMode: true
142146
})

packages/ipfs-unixfs-exporter/test/exporter.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,14 @@ describe('exporter', () => {
686686
expect(data).to.deep.equal(bigFile)
687687
})
688688

689+
it('reads an empty file', async () => {
690+
const data = await addAndReadTestFile({
691+
file: new Uint8Array()
692+
})
693+
694+
expect(data).to.have.property('byteLength', 0)
695+
})
696+
689697
it('returns an empty stream for dir', async () => {
690698
const imported = await first(importer([{
691699
path: 'empty'

0 commit comments

Comments
 (0)