Skip to content

Commit 6df8579

Browse files
pgtedaviddias
authored andcommitted
fix: dirs shouldn't have file size (#16)
1 parent 7f76569 commit 6df8579

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ const types = [
1515
'hamt-sharded-directory'
1616
]
1717

18+
const dirTypes = [
19+
'directory',
20+
'hamt-sharded-directory'
21+
]
22+
1823
function Data (type, data) {
1924
if (!(this instanceof Data)) {
2025
return new Data(type, data)
@@ -37,6 +42,11 @@ function Data (type, data) {
3742

3843
// data.length + blockSizes
3944
this.fileSize = () => {
45+
if (dirTypes.indexOf(this.type) >= 0) {
46+
// dirs don't have file size
47+
return undefined
48+
}
49+
4050
let sum = 0
4151
this.blockSizes.forEach((size) => {
4252
sum += size
@@ -63,7 +73,7 @@ function Data (type, data) {
6373
}
6474
let fileSize = this.fileSize()
6575

66-
if (fileSize === 0) {
76+
if (!fileSize) {
6777
fileSize = undefined
6878
}
6979

0 commit comments

Comments
 (0)