partially asynchronous msd

This commit is contained in:
Maxim Devaev
2023-03-16 01:32:05 +02:00
parent baf454bef9
commit 4d6da37f40
3 changed files with 35 additions and 28 deletions

View File

@@ -27,6 +27,7 @@ import time
from typing import AsyncGenerator
import aiofiles
import aiofiles.os
import aiofiles.base
from ...logging import get_logger
@@ -207,7 +208,7 @@ class MsdFileReader(BaseMsdReader): # pylint: disable=too-many-instance-attribu
async def open(self) -> "MsdFileReader":
assert self.__file is None
get_logger(1).info("Reading %r image from MSD ...", self.__name)
self.__file_size = os.stat(self.__path).st_size
self.__file_size = (await aiofiles.os.stat(self.__path)).st_size
self.__file = await aiofiles.open(self.__path, mode="rb") # type: ignore
return self
@@ -269,7 +270,7 @@ class MsdFileWriter(BaseMsdWriter): # pylint: disable=too-many-instance-attribu
async def open(self) -> "MsdFileWriter":
assert self.__file is None
get_logger(1).info("Writing %r image (%d bytes) to MSD ...", self.__name, self.__file_size)
os.makedirs(os.path.dirname(self.__path), exist_ok=True)
await aiofiles.os.makedirs(os.path.dirname(self.__path), exist_ok=True)
self.__file = await aiofiles.open(self.__path, mode="w+b", buffering=0) # type: ignore
return self