dev@locazia: fix file upload

This commit is contained in:
user committed 2024-03-08 03:27:20 +03:00
1 parent 27116f9a37
commit caf181e6c6
2 files changed
+4 -2

No files matched your search

+3 -1
View File
@@ -2,7 +2,9 @@
def string_to_bytes_fixed_size(src: str, size: int, encoding='utf-8') -> bytes:
assert type(src) is str, "src must be a string"
src_bin = src.encode(encoding)
assert len(src_bin) <= size, "src is too long"
while len(src_bin) > size:
src = src[:-1]
src_bin = src.encode(encoding)
return src_bin + b'\x00' * (size - len(src_bin))