Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit e937e21

Browse files
authored
Add the ability to use G (GiB) and T (TiB) suffixes in configuration options that refer to numbers of bytes. (#16219)
* Add more suffixes to `parse_size` * Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) <[email protected]> --------- Signed-off-by: Olivier Wilkinson (reivilibre) <[email protected]>
1 parent 698f6fa commit e937e21

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

changelog.d/16219.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add the ability to use `G` (GiB) and `T` (TiB) suffixes in configuration options that refer to numbers of bytes.

docs/usage/configuration/config_documentation.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ messages from the database after 5 minutes, rather than 5 months.
2525

2626
In addition, configuration options referring to size use the following suffixes:
2727

28-
* `M` = MiB, or 1,048,576 bytes
2928
* `K` = KiB, or 1024 bytes
29+
* `M` = MiB, or 1,048,576 bytes
30+
* `G` = GiB, or 1,073,741,824 bytes
31+
* `T` = TiB, or 1,099,511,627,776 bytes
3032

3133
For example, setting `max_avatar_size: 10M` means that Synapse will not accept files larger than 10,485,760 bytes
3234
for a user avatar.

synapse/config/_base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,9 @@ def parse_size(value: Union[str, int]) -> int:
179179
180180
If an integer is provided it is treated as bytes and is unchanged.
181181
182-
String byte sizes can have a suffix of 'K' or `M`, representing kibibytes and
183-
mebibytes respectively. No suffix is understood as a plain byte count.
182+
String byte sizes can have a suffix of 'K', `M`, `G` or `T`,
183+
representing kibibytes, mebibytes, gibibytes and tebibytes respectively.
184+
No suffix is understood as a plain byte count.
184185
185186
Raises:
186187
TypeError, if given something other than an integer or a string
@@ -189,7 +190,7 @@ def parse_size(value: Union[str, int]) -> int:
189190
if type(value) is int: # noqa: E721
190191
return value
191192
elif isinstance(value, str):
192-
sizes = {"K": 1024, "M": 1024 * 1024}
193+
sizes = {"K": 1024, "M": 1024 * 1024, "G": 1024**3, "T": 1024**4}
193194
size = 1
194195
suffix = value[-1]
195196
if suffix in sizes:

0 commit comments

Comments
 (0)