=============== LIBRARY RULES =============== From library maintainers: - Import from strip_bom: strip_bom (str), strip_bom_buffer (bytes), strip_bom_stream (binary file object), strip_bom_file (path). - strip_bom_buffer only removes the BOM when the bytes are valid UTF-8; strip_bom raises TypeError for bytes input. ### Install strip-bom with pip Source: https://github.com/ysskrishna/strip-bom/blob/main/README.md Install the strip-bom package from PyPI using pip. ```bash pip install strip-bom ``` -------------------------------- ### strip_bom(text: str) -> str Source: https://github.com/ysskrishna/strip-bom/blob/main/README.md Removes the Byte Order Mark (BOM) from a Unicode string. If the string does not start with a BOM, it is returned unchanged. ```APIDOC ## strip_bom(text: str) -> str ### Description Removes the Byte Order Mark (BOM) from a Unicode string. If the string does not start with a BOM, it is returned unchanged. ### Parameters - **text** (str) - Required - The input string to process. ### Returns - **str** - The string with BOM removed, or the original string if no BOM is present. ### Request Example ```python from strip_bom import strip_bom text_with_bom = '\ufeffunicorn' clean_text = strip_bom(text_with_bom) print(clean_text) # 'unicorn' # Text without BOM remains unchanged normal_text = 'Hello World' print(strip_bom(normal_text)) # 'Hello World' ``` ``` -------------------------------- ### strip_bom_file(file_path: str, mode: str = 'r') -> Union[str, bytes] Source: https://github.com/ysskrishna/strip-bom/blob/main/README.md Removes the BOM from the content of a file. The mode parameter determines whether the file is read as text (UTF-8) or binary. ```APIDOC ## strip_bom_file(file_path: str, mode: str = 'r') -> Union[str, bytes] ### Description Removes the BOM from the content of a file. The mode parameter determines whether the file is read as text (UTF-8) or binary. ### Parameters - **file_path** (str) - Required - The path to the file to process. - **mode** (str) - Optional - The file mode: 'r' or 'rt' for text (UTF-8), 'rb' for binary. Default is 'r'. ### Returns - **Union[str, bytes]** - The file content with BOM removed, as a string (text mode) or bytes (binary mode). ### Request Example ```python from strip_bom import strip_bom_file # Text mode (reads as UTF-8) content = strip_bom_file('data.txt', mode='r') print(f"File content: {content}") # Binary mode binary_content = strip_bom_file('data.txt', mode='rb') print(f"Binary content: {binary_content}") ``` ``` -------------------------------- ### Remove BOM from files with strip_bom_file Source: https://github.com/ysskrishna/strip-bom/blob/main/README.md Use strip_bom_file to remove a BOM from a file's content. Use mode='r' or 'rt' for text (UTF-8) and 'rb' for binary. ```python from strip_bom import strip_bom_file # Text mode (reads as UTF-8) content = strip_bom_file('data.txt', mode='r') print(f"File content: {content}") # Binary mode binary_content = strip_bom_file('data.txt', mode='rb') print(f"Binary content: {binary_content}") ``` -------------------------------- ### Process streams with strip_bom_stream Source: https://github.com/ysskrishna/strip-bom/blob/main/README.md Use strip_bom_stream to remove a BOM from a binary stream in chunks, avoiding loading the entire stream into memory. The default chunk size is 8192 bytes. ```python from strip_bom import strip_bom_stream import io # Process large streams without loading everything into memory stream = io.BytesIO(b'\xef\xbb\xbfLarge file content here...') # Process in chunks for chunk in strip_bom_stream(stream, chunk_size=8192): # Process each chunk as needed print(chunk) # Or get all content at once stream.seek(0) content = b''.join(strip_bom_stream(stream)) ``` -------------------------------- ### strip_bom_buffer(buffer: Union[bytes, bytearray]) -> bytes Source: https://github.com/ysskrishna/strip-bom/blob/main/README.md Removes the BOM from a bytes or bytearray object if it is valid UTF-8. If the input is not valid UTF-8, it is returned unchanged for safety. ```APIDOC ## strip_bom_buffer(buffer: Union[bytes, bytearray]) -> bytes ### Description Removes the BOM from a bytes or bytearray object if it is valid UTF-8. If the input is not valid UTF-8, it is returned unchanged for safety. ### Parameters - **buffer** (Union[bytes, bytearray]) - Required - The input buffer to process. ### Returns - **bytes** - The buffer with BOM removed, or the original buffer if it is not valid UTF-8. ### Request Example ```python from strip_bom import strip_bom_buffer bytes_with_bom = b'\xef\xbb\xbfunicorn' clean_bytes = strip_bom_buffer(bytes_with_bom) print(clean_bytes) # b'unicorn' # Invalid UTF-8 is left unchanged (safety first!) invalid_utf8 = b'\xef\xbb\xbf\xff\xfe' result = strip_bom_buffer(invalid_utf8) print(result == invalid_utf8) # True (no changes made) ``` ``` -------------------------------- ### strip_bom_stream(stream: BinaryIO, chunk_size: int = 8192) -> Iterator[bytes] Source: https://github.com/ysskrishna/strip-bom/blob/main/README.md Removes the BOM from a binary stream, yielding chunks of the processed data. This is memory-efficient for large streams. ```APIDOC ## strip_bom_stream(stream: BinaryIO, chunk_size: int = 8192) -> Iterator[bytes] ### Description Removes the BOM from a binary stream, yielding chunks of the processed data. This is memory-efficient for large streams. ### Parameters - **stream** (BinaryIO) - Required - The binary stream to process. - **chunk_size** (int) - Optional - The size of chunks to read and yield. Default is 8192. ### Returns - **Iterator[bytes]** - An iterator over chunks of the stream with BOM removed. ### Request Example ```python from strip_bom import strip_bom_stream import io # Process large streams without loading everything into memory stream = io.BytesIO(b'\xef\xbb\xbfLarge file content here...') # Process in chunks for chunk in strip_bom_stream(stream, chunk_size=8192): # Process each chunk as needed print(chunk) # Or get all content at once stream.seek(0) content = b''.join(strip_bom_stream(stream)) ``` ``` -------------------------------- ### Remove BOM from bytes with strip_bom_buffer Source: https://github.com/ysskrishna/strip-bom/blob/main/README.md Use strip_bom_buffer to remove a UTF-8 BOM from bytes or bytearray. Invalid UTF-8 input is left unchanged for safety. ```python from strip_bom import strip_bom_buffer bytes_with_bom = b'\xef\xbb\xbfunicorn' clean_bytes = strip_bom_buffer(bytes_with_bom) print(clean_bytes) # b'unicorn' # Invalid UTF-8 is left unchanged (safety first!) invalid_utf8 = b'\xef\xbb\xbf\xff\xfe' result = strip_bom_buffer(invalid_utf8) print(result == invalid_utf8) # True (no changes made) ``` -------------------------------- ### Remove BOM from strings with strip_bom Source: https://github.com/ysskrishna/strip-bom/blob/main/README.md Use strip_bom to remove a leading BOM from a Unicode string. Text without a BOM is returned unchanged. ```python from strip_bom import strip_bom text_with_bom = '\ufeffunicorn' clean_text = strip_bom(text_with_bom) print(clean_text) # 'unicorn' # Text without BOM remains unchanged normal_text = 'Hello World' print(strip_bom(normal_text)) # 'Hello World' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.