File#
- ignis.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 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.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 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.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 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.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 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)