doc/read_file_
This commit is contained in:
parent
6fab5ce9b4
commit
094d66bc33
1 changed files with 22 additions and 3 deletions
|
@ -67,18 +67,37 @@ def make_directory(path: Path) -> None:
|
||||||
|
|
||||||
|
|
||||||
def read_file_bytes(file_path: Path) -> bytes:
|
def read_file_bytes(file_path: Path) -> bytes:
|
||||||
"""Read whole file bytes."""
|
"""Read whole file bytes.
|
||||||
|
|
||||||
|
:param file_path: source input file
|
||||||
|
:type file_path: Path
|
||||||
|
:rtype: bytes
|
||||||
|
"""
|
||||||
with file_path.open("br") as file_object:
|
with file_path.open("br") as file_object:
|
||||||
return file_object.read()
|
return file_object.read()
|
||||||
|
|
||||||
|
|
||||||
def read_file_lines(file_path: Path, charset: str = CHARSET) -> list[str]:
|
def read_file_lines(file_path: Path, charset: str = CHARSET) -> list[str]:
|
||||||
"""Read whole file lines."""
|
"""Read whole file lines.
|
||||||
|
|
||||||
|
:param file_path: source input file
|
||||||
|
:type file_path: Path
|
||||||
|
:param charset: charset to use for decoding input
|
||||||
|
:type charset: str
|
||||||
|
:rtype: list[str]
|
||||||
|
"""
|
||||||
return read_file_text(file_path, charset).split(os.linesep)
|
return read_file_text(file_path, charset).split(os.linesep)
|
||||||
|
|
||||||
|
|
||||||
def read_file_text(file_path: Path, charset: str = CHARSET) -> str:
|
def read_file_text(file_path: Path, charset: str = CHARSET) -> str:
|
||||||
"""Read whole file text."""
|
"""Read whole file text.
|
||||||
|
|
||||||
|
:param file_path: source input file
|
||||||
|
:type file_path: Path
|
||||||
|
:param charset: charset to use for decoding input
|
||||||
|
:type charset: str
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
return read_file_bytes(file_path).decode(charset)
|
return read_file_bytes(file_path).decode(charset)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue