mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-31 01:51:53 +08:00
partially asynchronous msd
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user