fs.read_file_object
This commit is contained in:
parent
edd8e15978
commit
5eae0334de
2 changed files with 15 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import tomllib
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from rwx import ps
|
from rwx import ps
|
||||||
|
@ -106,6 +107,19 @@ def read_file_lines(file_path: Path, charset: str = CHARSET) -> 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_object(file_path: Path, charset: str = CHARSET) -> object:
|
||||||
|
"""Read whole file as toml object.
|
||||||
|
|
||||||
|
:param file_path: source input file
|
||||||
|
:type file_path: Path
|
||||||
|
:param charset: charset to use for decoding input
|
||||||
|
:type charset: str
|
||||||
|
:rtype: object
|
||||||
|
"""
|
||||||
|
text = read_file_text(file_path, charset)
|
||||||
|
return tomllib.loads(text)
|
||||||
|
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
"""Output FreeTube db."""
|
"""Output FreeTube db."""
|
||||||
|
|
||||||
|
|
||||||
def to_db(value: object) -> str:
|
def to_db(value: object) -> str:
|
||||||
"""Render value as string.
|
"""Render value as string.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue