Skip to content

feat: Download.createReadStream()#151

Closed
mxschmitt wants to merge 2 commits into
microsoft:masterfrom
mxschmitt:feature/Download-createReadStream
Closed

feat: Download.createReadStream()#151
mxschmitt wants to merge 2 commits into
microsoft:masterfrom
mxschmitt:feature/Download-createReadStream

Conversation

@mxschmitt
Copy link
Copy Markdown
Contributor

@mxschmitt mxschmitt commented Aug 5, 2020

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 by io in our generation scripts?

Relates #144

@coveralls
Copy link
Copy Markdown

coveralls commented Aug 5, 2020

Pull Request Test Coverage Report for Build 198231595

Warning: 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

  • 67 of 73 (91.78%) changed or added relevant lines in 7 files are covered.
  • 3 unchanged lines in 3 files lost coverage.
  • Overall coverage remained the same at 89.978%

Changes Missing Coverage Covered Lines Changed/Added Lines %
playwright/download.py 7 8 87.5%
scripts/documentation_provider.py 5 6 83.33%
playwright/async_api.py 14 16 87.5%
playwright/sync_api.py 14 16 87.5%
Files with Coverage Reduction New Missed Lines %
playwright/async_api.py 1 92.43%
playwright/connection.py 1 97.62%
playwright/sync_api.py 1 68.91%
Totals Coverage Status
Change from base Build 198064508: 0.0%
Covered Lines: 3735
Relevant Lines: 4151

💛 - Coveralls

Comment thread playwright/async_api.py

Returns readable stream for current download or `null` if download failed.

Parameters
Copy link
Copy Markdown
Member

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...

Comment thread playwright/stream.py Outdated
fp = io.BytesIO()

while True:
result = await self._channel.send("read", dict(size=1))
Copy link
Copy Markdown
Member

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!

Copy link
Copy Markdown
Contributor Author

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?

@mxschmitt mxschmitt force-pushed the feature/Download-createReadStream branch 3 times, most recently from 913b0c4 to affc58e Compare August 5, 2020 22:41
Comment thread playwright/sync_api.py Outdated
Comment thread playwright/stream.py Outdated
) -> None:
super().__init__(parent, type, guid, initializer)

async def stream(self, fp: io.BytesIO, size: Optional[int]) -> io.BytesIO:
Copy link
Copy Markdown
Member

@pavelfeldman pavelfeldman Aug 6, 2020

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?

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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.

@mxschmitt mxschmitt force-pushed the feature/Download-createReadStream branch from affc58e to a657741 Compare August 6, 2020 18:14
self.printed_entries: List[str] = []
with open("api.json") as json_file:
self.api = json.load(json_file)
self.api["StreamIO"] = {
Copy link
Copy Markdown
Member

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.

@mxschmitt mxschmitt closed this Sep 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants