Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dirs shouldn't have file size #16

Merged
merged 1 commit into from
Jun 16, 2017
Merged
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
12 changes: 11 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ const types = [
'hamt-sharded-directory'
]

const dirTypes = [
'directory',
'hamt-sharded-directory'
]

function Data (type, data) {
if (!(this instanceof Data)) {
return new Data(type, data)
Expand All @@ -37,6 +42,11 @@ function Data (type, data) {

// data.length + blockSizes
this.fileSize = () => {
if (dirTypes.indexOf(this.type) >= 0) {
// dirs don't have file size
return undefined
}

let sum = 0
this.blockSizes.forEach((size) => {
sum += size
Expand All @@ -63,7 +73,7 @@ function Data (type, data) {
}
let fileSize = this.fileSize()

if (fileSize === 0) {
if (!fileSize) {
fileSize = undefined
}

Expand Down