Skip to content

Commit d7a6c07

Browse files
committed
add aio module for async I/O support
1 parent 64dcfe1 commit d7a6c07

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/fdiff/aio.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import aiofiles
2+
3+
4+
async def async_write_bin(path, binary):
5+
"""Asynchronous IO writes of binary data `binary` to disk on the file path `path`"""
6+
async with aiofiles.open(path, "wb") as f:
7+
await f.write(binary)

tests/test_aio.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import os
2+
import tempfile
3+
4+
import pytest
5+
6+
from fdiff.aio import async_write_bin
7+
8+
9+
@pytest.mark.asyncio
10+
async def test_async_write():
11+
with tempfile.TemporaryDirectory() as tmpdirname:
12+
test_path = os.path.join(tmpdirname, "test.bin")
13+
await async_write_bin(test_path, b"test")
14+
assert os.path.exists(test_path) is True
15+
with open(test_path, "rb") as f:
16+
res = f.read()
17+
assert res == b"test"

0 commit comments

Comments
 (0)