-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
639d59c
commit f9a0281
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from __future__ import annotations | ||
|
||
from os import PathLike | ||
|
||
from quart.datastructures import FileStorage | ||
from trio import open_file, Path, wrap_file | ||
|
||
|
||
class TrioFileStorage(FileStorage): | ||
async def save(self, destination: PathLike, buffer_size: int = 16384) -> None: # type: ignore | ||
wrapped_stream = wrap_file(self.stream) | ||
async with await open_file(destination, "wb") as file_: | ||
data = await wrapped_stream.read(buffer_size) | ||
while data != b"": | ||
await file_.write(data) | ||
data = await wrapped_stream.read(buffer_size) | ||
|
||
async def load(self, source: PathLike, buffer_size: int = 16384) -> None: | ||
path = Path(source) | ||
self.filename = path.name | ||
wrapped_stream = wrap_file(self.stream) | ||
async with await open_file(path, "rb") as file_: | ||
data = await file_.read(buffer_size) | ||
while data != b"": | ||
await wrapped_stream.write(data) | ||
data = await file_.read(buffer_size) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from quart.formparser import FormDataParser | ||
|
||
from quart_trio.datastructures import TrioFileStorage | ||
|
||
|
||
class TrioFormDataParser(FormDataParser): | ||
file_storage_class = TrioFileStorage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters