File#
- ignis.utils.Utils.read_file(path: str | None = None, uri: str | None = None, gfile: Gio.File | None = None, decode: bool = True) str | bytes #
Read the contents of a file.
- Parameters:
- Returns:
The contents of the file.
At least one of the arguments,
path
,uri
, orgfile
, must be provided.Example usage:
from ignis.utils import Utils # regular file contents = Utils.read_file(path="/path/to/file", decode=True) print(contents) # URI Utils.read_file(uri="file:///path/to/file", decode=True) # Web also supported Utils.read_file(uri="https://SOME_SITE.org/example_content", decode=False)
- async ignis.utils.Utils.read_file_async(path: str | None = None, uri: str | None = None, gfile: Gio.File | None = None, decode: bool = True) str | bytes #
Asynchronously read the contents of a file.
- Parameters:
- Returns:
The contents of the file.
At least one of the arguments,
path
,uri
, orgfile
, must be provided.Example usage:
import asyncio from ignis.utils import Utils async def some_func() -> None: # regular file res1 = await Utils.read_file_async(path="/path/to/file", decode=True) print("Contents 1: ", res1) # URI res2 = await Utils.read_file_async(uri="file:///path/to/file", decode=True) print("Contents 2: ", res2) # Web also supported res3 = await Utils.read_file_async(uri="https://SOME_SITE.org/example_content", decode=False) print("Contents 3: ", res3) asyncio.create_task(some_func())
- ignis.utils.Utils.write_file(path: str | None = None, uri: str | None = None, gfile: Gio.File | None = None, contents: bytes | None = None, string: str | None = None) None #
Write contents to a file.
- Parameters:
path (default:
None
) -- The path to the file.uri (default:
None
) -- The URI of the file.gfile (default:
None
) -- An instance ofGio.File
.contents (default:
None
) -- The bytes to write to the file.string (default:
None
) -- The string to write to the file.
At least one of the arguments,
path
,uri
, orgfile
, must be provided. Eithercontents
orstring
must be provided.Example usage:
import asyncio from ignis.utils import Utils async def some_write_func() -> None: # write string await Utils.write_file(path="/path/to/file", string="some_string") # or bytes await Utils.write_file(path="/path/to/file", bytes=b"some bytes") asyncio.create_task(some_write_func())
- async ignis.utils.Utils.write_file_async(path: str | None = None, uri: str | None = None, gfile: Gio.File | None = None, contents: bytes | None = None, string: str | None = None) None #
Asynchronously write contents to a file.
- Parameters:
path (default:
None
) -- The path to the file.uri (default:
None
) -- The URI of the file.gfile (default:
None
) -- An instance ofGio.File
.contents (default:
None
) -- The bytes to write to the file.string (default:
None
) -- The string to write to the file.callback -- A function to call when the operation is complete.
*user_data -- User data to pass to
callback
.
At least one of the arguments,
path
,uri
, orgfile
, must be provided. Eithercontents
orstring
must be provided.Example usage:
from ignis.utils import Utils def some_callback() -> None: print("Operation is complete") # write string Utils.write_file_async(path="/path/to/file", string="some_string", callback=some_callback) # or bytes Utils.write_file_async(path="/path/to/file", bytes=b"some bytes", callback=some_callback)