Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/juancarlospaco/nim-bytes2human
Calculate all Byte units from integer bytes positive int64 with precision from Bytes to Yottabytes and return a human friendly string representation.
https://github.com/juancarlospaco/nim-bytes2human
bytes human human-friendly nim nim-language
Last synced: 21 days ago
JSON representation
Calculate all Byte units from integer bytes positive int64 with precision from Bytes to Yottabytes and return a human friendly string representation.
- Host: GitHub
- URL: https://github.com/juancarlospaco/nim-bytes2human
- Owner: juancarlospaco
- License: lgpl-3.0
- Created: 2018-05-04T10:17:29.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-02-11T01:02:57.000Z (over 3 years ago)
- Last Synced: 2024-08-04T01:15:00.858Z (3 months ago)
- Topics: bytes, human, human-friendly, nim, nim-language
- Language: Nim
- Size: 21.5 KB
- Stars: 12
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Nim-Bytes2Human
Calculate all Byte units from integer bytes positive `int64`,
with precision from Bytes to Yottabytes, and return a human friendly string representation.- Works with `--gc:arc`, `--gc:orc`, `--panics:on`, `--experimental:strictFuncs`, C, C++, JavaScript.
- Uses `system.nim` only, does not import anything from stdlib. Good performance.# Use
```nim
>>> import bytes2human
>>> echo bytes2human(2398345659434540923) # 2 Exabytes.
(human: "2 Exabytes 82 Petabytes 162 Terabytes 686 Gigabytes 371 Megabytes 136 Kilobytes 891 Bytes", short: "2 Exabytes", units: (bite: 891, kilo: 136, mega: 371, giga: 686, tera: 162, peta: 82, exa: 2, zetta: 0))
>>> echo bytes2human(1027) # 1 Kilobytes.
(human: "1 Kilobytes 3 Bytes", short: "1 Kilobytes", units: (bite: 3, kilo: 1, mega: 0, giga: 0, tera: 0, peta: 0, exa: 0, zetta: 0))
>>> echo bytes2human(0) # 0 Byte.
(human: "0 Bytes", short: "0 Bytes", units: (bite: 0, kilo: 0, mega: 0, giga: 0, tera: 0, peta: 0, exa: 0, zetta: 0))
>>> echo bytes2human(-666) # Invalid!.
Error: unhandled exception: 0 <= integer_bytes Invalid Negative value for integer_bytes!. [AssertionError]
>>>
```# Install
```
nimble install bytes2human
```# Requisites
- [Nim](https://nim-lang.org)
# Documentation
`bytes2human()`
**Description:**
Calculate Bytes, with precision from Bytes to Yottabytes.
Calculate all Byte units from integer_bytes positive integer.
The proc only accepts `int64`.**Arguments:**
- `integer_bytes` Bytes size, positive `int64` type, required.**Returns:** `HumanBytes` type, a tuple.