Skip to content

Commit

Permalink
Draft docs for parse_bytes function
Browse files Browse the repository at this point in the history
  • Loading branch information
titaneric committed Dec 28, 2024
1 parent 029a2ff commit 731da85
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions website/cue/reference/remap/functions/parse_bytes.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package metadata

remap: functions: parse_bytes: {
category: "Parse"
description: """
Parses the `value` into a human-readable bytes format specified by `unit` and `base`.
"""

arguments: [
{
name: "value"
description: "The string of the duration with either binary or SI unit."
required: true
type: ["string"]
},
{
name: "unit"
description: "The output units for the byte."
required: true
type: ["string"]
enum: {
B: "Bytes"
kiB: "Kilobytes (1024 bytes)"
MiB: "Megabytes (1024 ** 2 bytes)"
GiB: "Gigabytes (1024 ** 3 bytes)"
TiB: "Terabytes (1024 gigabytes)"
PiB: "Petabytes (1024 ** 2 gigabytes)"
EiB: "Exabytes (1024 ** 3 gigabytes)"

Check warning on line 28 in website/cue/reference/remap/functions/parse_bytes.cue

View workflow job for this annotation

GitHub Actions / Check Spelling

`Exabytes` is not a recognized word. (unrecognized-spelling)
kB: "Kilobytes (1 thousand bytes in SI)"
MB: "Megabytes (1 million bytes in SI)"
GB: "Gigabytes (1 billion bytes in SI)"
TB: "Terabytes (1 thousand gigabytes in SI)"
PB: "Petabytes (1 million gigabytes in SI)"
EB: "Exabytes (1 billion gigabytes in SI)"

Check warning on line 34 in website/cue/reference/remap/functions/parse_bytes.cue

View workflow job for this annotation

GitHub Actions / Check Spelling

`Exabytes` is not a recognized word. (unrecognized-spelling)
}
},
{
name: "base"
description: "The base for the byte, either 2 or 10."
required: false
type: ["string"]
default: 2
},
]
internal_failure_reasons: [
"`value` is not a properly formatted bytes.",
]
return: types: ["float"]

examples: [
{
title: "Parse bytes (kilobytes)"
source: #"""
parse_duration!("1024KiB", unit: "MiB")
"""#
return: 1.0
},
{
title: "Parse bytes in SI unit (terabytes)"
source: #"""
parse_duration!("4TiB", unit: "MiB", base: "10")
"""#
return: 4000000.0
},
{
title: "Parse bytes in ambiguous unit (gigabytes)"
source: #"""
parse_duration!("1GB", unit: "B", base: "2")
"""#
return: 1073741824.0
},
]
}

0 comments on commit 731da85

Please sign in to comment.