Skip to main content

write_truncated_to_limited_bytes

No overview available.

def write_truncated_to_limited_bytes(
f: BinaryIO,
s: str,
limit: int,
encoding: str = utf-8
) - > int

Writes a string to a file-like object while ensuring the total output does not exceed a specified byte limit.

Parameters

NameTypeDescription
fBinaryIOThe file-like object or buffer where the encoded string will be written.
sstrThe input string to be encoded and written.
limitintThe maximum number of bytes allowed to be written to the output.
encodingstr = utf-8The character encoding used to convert the string into bytes.

Returns

TypeDescription
intThe total number of bytes actually written to the file-like object.