Example 1¶
Save a text file asynchronously to your local filesystem
In [ ]:
Copied!
import asyncio
from morefs.asyn_local import AsyncLocalFileSystem
from pathlib import Path
fp = "/tmp/ganymede_demo"
tfp = f"{fp}/test.txt"
path = Path(fp).mkdir(exist_ok=True)
async def main():
fs = AsyncLocalFileSystem(auto_mkdir=False)
async with fs.open_async(tfp, mode="w") as f:
await f.write("foobar")
content = await fs._cat(tfp)
print(content)
# Alternatively, you can still use sync methods
print(fs.cat(tfp))
asyncio.run(main())
import asyncio
from morefs.asyn_local import AsyncLocalFileSystem
from pathlib import Path
fp = "/tmp/ganymede_demo"
tfp = f"{fp}/test.txt"
path = Path(fp).mkdir(exist_ok=True)
async def main():
fs = AsyncLocalFileSystem(auto_mkdir=False)
async with fs.open_async(tfp, mode="w") as f:
await f.write("foobar")
content = await fs._cat(tfp)
print(content)
# Alternatively, you can still use sync methods
print(fs.cat(tfp))
asyncio.run(main())