Generator for chunks of content stream
メンテナーはふだん 1 日以内に返信
@jmoldow がすでに取り組んでいます。
2015年12月14日 から。
評価
この issue はまだ評価されていません。
説明
Today, there are two options for downloading a file:
File.content(), which requests the entire file at once, and loads it all into memory.File.download_to(), which requests the file in chunks, and dumps it into a stream (filehandle or another instance ofio.IOBase).
The first option always loads the full contents into memory. The second option always loads the full contents into memory except in the case where the stream is a file handle. Additionally, both options always download the full file before handing control back to the caller.
There should be a third option for download, which only downloads and loads individual chunks at a time, and is a generator and therefore hands control back to the caller for each chunk.
I've implemented this both locally and in a comment on #93, and it looks something like this:
from contextlib import contextmanager, closing
class File(Item):
...
# A contextmanager so that we can force the HTTP stream to be closed when we're done with it.
@contextmanager
def content_chunks(self):
url = self.get_url('content')
with closing(self._session.get(url, expect_json_response=False, stream=True)) as box_response:
yield box_response.network_response.response_as_stream().stream(decode_content=True)
# We can redefine download_to() in terms of content_chunks().
def download_to(self, writeable_stream):
with self.content_chunks() as chunks:
for chunk in chunks:
writeable_stream.write(chunk)
# Usage example 1
with my_file.content_chunks() as chunks:
for chunk in chunks:
# Handle chunk
# Usage example 2
with my_file.content_chunks() as chunks:
# Handle chunks
This could be added as-is, but I haven't created a PR yet because I wanted to think more about #87. I was wondering if there might be a better way to expose streams in the abstract Network interface. Right now we have a generic response_as_stream() method on NetworkResponse, but it isn't really generic because:
- It requires
stream=Trueto be passed torequest()onNetwork, which isn't documented because it is specific to the requests library. - After calling
response_as_stream(), you must call itsstream()method, which isn't documented because it is specific to the requests library.
We could just add this as-is, because it doesn't technically add any additional dependencies on requests that weren't already added via download_to().
- 主要言語
- Python
- スター
- 460
- フォーク
- 223
- 平均マージ
- 10時間 31分
- マージ済み PR(30日)
- 22
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
box/box-python-sdk のほかの issue
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
box/box-python-sdk#196 ·
メンテナーはふだん 1 日以内に返信
-
JTI claim value is not getting regenerated if API calls fails due to rate limit再び着手できるかも @mwwoda が 282 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンbug enhancement
box/box-python-sdk#1314 · コメント 6 件 · 担当者 5 名 ·
メンテナーはふだん 1 日以内に返信
-
Missing py.typed marker in box_sdk_gen causes mypy import-untyped error再び着手できるかも @mwwoda が 386 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンenhancement
box/box-python-sdk#1154 · コメント 3 件 · 担当者 5 名 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
box/box-python-sdk#1155 · コメント 1 件 · リアクション 4 件 ·
メンテナーはふだん 1 日以内に返信
-
Implement `__eq__` for CreateFolderParent class再び着手できるかも @mwwoda が 649 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンenhancement
box/box-python-sdk#1157 · コメント 1 件 · 担当者 6 名 ·
メンテナーはふだん 1 日以内に返信
box/box-python-sdk の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
solana-foundation/pay-kit#341 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
nasa/python_cmr#123 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
EleutherAI/lm-evaluation-harness#4243 ·
メンテナーはふだん 1 日以内に返信
-
area: dashboard bug perceived difficulty: 3
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
Nitjsefnie-Harness-Commons/daedalus#1179 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
cusp-ai-oss/tojax#17 ·