-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: Download.createReadStream() #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No parameters because we could not find fp in api.json. We should still list those w/o docs...
playwright/stream.py
Outdated
fp = io.BytesIO() | ||
|
||
while True: | ||
result = await self._channel.send("read", dict(size=1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you reading single byte at a time? Probably not too efficient!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
playwright/stream.py
Outdated
) -> 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
io
type generation handling was not working as expected, maybe you can take a look? Do I need to replace_io
byio
in our generation scripts?Relates #144