本文整理汇总了Python中typing.BinaryIO.write方法的典型用法代码示例。如果您正苦于以下问题:Python BinaryIO.write方法的具体用法?Python BinaryIO.write怎么用?Python BinaryIO.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类typing.BinaryIO
的用法示例。
在下文中一共展示了BinaryIO.write方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_to
# 需要导入模块: from typing import BinaryIO [as 别名]
# 或者: from typing.BinaryIO import write [as 别名]
async def save_to(self, name: str, fd: BinaryIO):
async with ClientSession() as client:
async with client.post(self.get_url, data=name.encode("utf8")) as resp:
assert resp.status == 200
while True:
data = await resp.content.read(2 << 20)
if not data:
break
fd.write(data)
示例2: download_into
# 需要导入模块: from typing import BinaryIO [as 别名]
# 或者: from typing.BinaryIO import write [as 别名]
def download_into(session: requests.Session,
url: str, file: BinaryIO, process_func=None) -> None:
r = session.get(url, stream=True)
length = int(r.headers.get('Content-Length') or 0)
received = 0
for chunk in r.iter_content(CHUNK_SIZE):
received += len(chunk)
file.write(chunk)
if process_func:
process_func(received, length)
if not length and process_func:
process_func(received, received)
示例3: postprocess
# 需要导入模块: from typing import BinaryIO [as 别名]
# 或者: from typing.BinaryIO import write [as 别名]
def postprocess(self, source: ArchiveView, sink: BinaryIO) -> None:
if self.details:
key, amount = self.details
parts = []
while amount > 0:
part = source.read(amount)
amount -= len(part)
parts.append(part)
sink.write(obfuscation_run(b"".join(parts), key))
else:
raise Exception("find_offset_and_key must be called before postprocess")
for segment in iter(source.read1, b""):
sink.write(segment)
示例4: _rewrite_ownership_v0
# 需要导入模块: from typing import BinaryIO [as 别名]
# 或者: from typing.BinaryIO import write [as 别名]
def _rewrite_ownership_v0(
input_file: BinaryIO, new_file: BinaryIO, header: MdvHeader, uid: int, gid: int
) -> None:
entries_processed = 0
entry_size = InodeMetadataV0.FORMAT.size
for _ in range(header.entry_count):
entries_processed += 1
entry_data = input_file.read(entry_size)
if len(entry_data) != entry_size:
raise Exception("inode metadata table appears truncated")
entry = InodeMetadataV0.parse(entry_data)
entry.uid = uid
entry.gid = gid
new_file.write(entry.serialize())
# Copy the remaining file contents as is. This is normally all 0-filled data
# that provides space for new entries to be written in the future.
padding = input_file.read()
new_file.write(padding)
示例5: dump
# 需要导入模块: from typing import BinaryIO [as 别名]
# 或者: from typing.BinaryIO import write [as 别名]
def dump(value: TSerializable, file_handle: typing.BinaryIO) -> None:
"""
This function dumps a python object as a tnetstring and
writes it to the given file.
"""
file_handle.write(dumps(value))
示例6: postprocess
# 需要导入模块: from typing import BinaryIO [as 别名]
# 或者: from typing.BinaryIO import write [as 别名]
def postprocess(self, source: ArchiveView, sink: BinaryIO) -> None:
"""Allows postprocessing over the data extracted from the archive."""
for segment in iter(source.read1, b""):
sink.write(segment)