Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
de2cb5d8
Commit
de2cb5d8
authored
Jan 20, 2015
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: extract thirdparty/unit
parent
121061b6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
0 deletions
+72
-0
thirdparty/unit/unit.go
thirdparty/unit/unit.go
+46
-0
thirdparty/unit/unit_test.go
thirdparty/unit/unit_test.go
+26
-0
No files found.
thirdparty/unit/unit.go
0 → 100644
View file @
de2cb5d8
package
unit
import
"fmt"
type
Information
int64
const
(
_
Information
=
iota
// ignore first value by assigning to blank identifier
KB
=
1
<<
(
10
*
iota
)
MB
GB
TB
PB
EB
)
func
(
i
Information
)
String
()
string
{
tmp
:=
int64
(
i
)
// default
var
d
int64
=
tmp
symbol
:=
"B"
switch
{
case
i
>
EB
:
d
=
tmp
/
EB
symbol
=
"EB"
case
i
>
PB
:
d
=
tmp
/
PB
symbol
=
"PB"
case
i
>
TB
:
d
=
tmp
/
TB
symbol
=
"TB"
case
i
>
GB
:
d
=
tmp
/
GB
symbol
=
"GB"
case
i
>
MB
:
d
=
tmp
/
MB
symbol
=
"MB"
case
i
>
KB
:
d
=
tmp
/
KB
symbol
=
"KB"
}
return
fmt
.
Sprintf
(
"%d %s"
,
d
,
symbol
)
}
thirdparty/unit/unit_test.go
0 → 100644
View file @
de2cb5d8
package
unit
import
"testing"
// and the award for most meta goes to...
func
TestByteSizeUnit
(
t
*
testing
.
T
)
{
if
1
*
KB
!=
1
*
1024
{
t
.
Fatal
(
1
*
KB
)
}
if
1
*
MB
!=
1
*
1024
*
1024
{
t
.
Fail
()
}
if
1
*
GB
!=
1
*
1024
*
1024
*
1024
{
t
.
Fail
()
}
if
1
*
TB
!=
1
*
1024
*
1024
*
1024
*
1024
{
t
.
Fail
()
}
if
1
*
PB
!=
1
*
1024
*
1024
*
1024
*
1024
*
1024
{
t
.
Fail
()
}
if
1
*
EB
!=
1
*
1024
*
1024
*
1024
*
1024
*
1024
*
1024
{
t
.
Fail
()
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment