import dascore as dc
from dascore.units import get_byte_count
assert get_byte_count(25 * dc.units.megabytes) == 25_000_000
assert get_byte_count(dc.get_quantity("1 MiB")) == 1_048_576get_byte_count
get_byte_count(
value: Quantity ,
)-> ‘float’
Return the number of bytes a data size quantity represents.
Parameters
| Parameter | Description |
|---|---|
| value | A quantity of information (eg 25 * dc.units.megabytes). |
Note
This is the only correct way to get a byte count from a quantity. In particular to_float is not: pint converts a dimensionless quantity to its base units, which for information is bits, so anything routing a size through a plain float() conversion is eight times too large.