8000 Add option to change file size units from decimal (SI) to binary (ISO/IEC) prefixes (like in ranger/ls) · Issue #1098 · gokcehan/lf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content 8000
Add option to change file size units from decimal (SI) to binary (ISO/IEC) prefixes (like in ranger/ls) #1098
Open
@Andrew15-5

Description

@Andrew15-5

My issue is somewhat related to #49.

I am working with files right now and was checking theirs sizes:

ls: 910M

ranger: 910M

lf (set info size): 954M

ls (bytes): 954148141

As you can see, lf is the only one which shows wrong number but with the same prefix (M). I would like to see an option to switch between metric/SI and binary units.

After a quick search, I think the only thing should be changed to switch to binary prefix is all 1000 replace with 1024 (of course a new setting should be also implemented):

lf/misc.go

Lines 209 to 235 in cb7aa13

if size < 1000 {
return fmt.Sprintf("%dB", size)
}
suffix := []string{
"K", // kilo
"M", // mega
"G", // giga
"T", // tera
"P", // peta
"E", // exa
"Z", // zeta
"Y", // yotta
}
curr := float64(size) / 1000
for _, s := range suffix {
if curr < 10 {
return fmt.Sprintf("%.1f%s", curr-0.0499, s)
} else if curr < 1000 {
return fmt.Sprintf("%d%s", int(curr), s)
}
curr /= 1000
}
return ""
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0