feat: Download.createReadStream()#151
Conversation
Pull Request Test Coverage Report for Build 198231595Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
|
|
||
| Returns readable stream for current download or `null` if download failed. | ||
|
|
||
| Parameters |
There was a problem hiding this comment.
No parameters because we could not find fp in api.json. We should still list those w/o docs...
| fp = io.BytesIO() | ||
|
|
||
| while True: | ||
| result = await self._channel.send("read", dict(size=1)) |
There was a problem hiding this comment.
Are you reading single byte at a time? Probably not too efficient!
There was a problem hiding this comment.
Oh ye good catch you won! Currently its not possible to leave out the size, thats why I set it to Node.js default value.
Probably we have to mark it in the protocol as optional so Node.js alone handles the default value?
913b0c4 to
affc58e
Compare
| ) -> None: | ||
| super().__init__(parent, type, guid, initializer) | ||
|
|
||
| async def stream(self, fp: io.BytesIO, size: Optional[int]) -> io.BytesIO: |
There was a problem hiding this comment.
I don't understand the version that returns the stream. It looks like it'll create one on line 30 and then read all content into its buffer? So there isn't much streaming going on?
There was a problem hiding this comment.
Looks like you need to subclass https://docs.python.org/3/library/io.html#io.RawIOBase in your stream instead.
There was a problem hiding this comment.
True, we should probably rename it. But in the Python world there are no streams like in Node.js, thats why I used this approach.
Could be used for writing into files or getting the content als a BytesIO stream.
Their documentation says for io.BytesIO:
A stream implementation using an in-memory bytes buffer. It inherits BufferedIOBase. The buffer is discarded when the close() method is called.
If we have another name we don't have documentation on the other hand, I would keep the name probably.
affc58e to
a657741
Compare
| self.printed_entries: List[str] = [] | ||
| with open("api.json") as json_file: | ||
| self.api = json.load(json_file) | ||
| self.api["StreamIO"] = { |
There was a problem hiding this comment.
I don't think we need these - these classes are not a part of the API, they don't need to be exposed. Just a helper class that converts channel into the stream is seemingly all we need.
I think thats the "idiomatic python way" of that. works basically like
json.dump.The
iotype generation handling was not working as expected, maybe you can take a look? Do I need to replace_iobyioin our generation scripts?Relates #144