pipeline.domain.measures.FileSize

class FileSize(value: int | float | Decimal = 0, units: dict = {'bytes': Decimal('1048576'), 'name': 'MEGABYTES', 'symbol': 'Mb'})[source]

Bases: ComparableUnit

Methods

convert_to

Converts this measure of file size to the new units.

to_units

Returns the magnitude of this file size in otherUnits.

Attributes

value

units

__init__(value: int | float | Decimal = 0, units: dict = {'bytes': Decimal('1048576'), 'name': 'MEGABYTES', 'symbol': 'Mb'}) None[source]

Creates a new file size with the given magnitude and units.

If called without arguments, the constructor will create a default size of 0 megabytes.

Parameters:
  • value -- The magnitude for this file size.

  • units -- The new units for this file size.

convert_to(newUnits: dict = {'bytes': Decimal('1048576'), 'name': 'MEGABYTES', 'symbol': 'Mb'}) FileSize[source]

Converts this measure of file size to the new units.

After this method is complete this file size will have units of newUnits and its value will have been converted accordingly.

Parameters:

newUnits -- The new units for this file size.

Returns:

this file size. The reason for this return type is to allow code of this nature:

gigabytes = myFileSize.convert_to(FileSizeUnits.GIGABYTES)

to_units(otherUnits: dict = {'bytes': Decimal('1073741824'), 'name': 'GIGABYTES', 'symbol': 'Gb'}) Decimal[source]

Returns the magnitude of this file size in otherUnits.

Note that this method does not alter the state of this file size. Contrast this with convert_to(FileSizeUnits).

Parameters:

otherUnits -- the units in which to express this file size's magnitude. If newUnits is None, it will be treated as FileSizeUnits.GIGABYTES.

Returns:

this file size's value converted to otherUnits.