本文整理汇总了Python中packet.Packet.binary_blob方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.binary_blob方法的具体用法?Python Packet.binary_blob怎么用?Python Packet.binary_blob使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类packet.Packet
的用法示例。
在下文中一共展示了Packet.binary_blob方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: transfer_file
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import binary_blob [as 别名]
def transfer_file(self, share_ID, file_name, return_address, start_offset=0, end_offset=999999999999, block_skip=1):
"""Sends a piece of a file to a peer in pieces.
Initiated by JSONRPC: get_file()
start_offset: start sending file from this offset
end_offset: if this bytes is reached, send no more.
block_skip: send a block, then skip this many blocks, then send the next etc.
"""
#continue to send all file blocks
full_file_path = os.path.join(self.storage_directory, share_ID, file_name)
f = open(full_file_path, 'rb')
f.seek(start_offset)
block_size = 5
file_offset = start_offset
logging.debug('file_name: %s start_offset: %d, end_offset: %d' %(file_name, start_offset, end_offset))
while (file_offset < end_offset): #@TODO: stop sending if given signal from return_address
logging.debug('file_offset: %d' %(file_offset))
block_bytes = f.read(64*block_size)
if block_bytes == "":
logging.debug('no bytes read from file')
break
p_out_block = Packet()
p_out_block.json_RPC_object = dict(jsonrpc="2.0", method="save_file_block", params=[1.0, None, [self.my_machine_ID, share_ID, file_name, file_offset]], ) #id=rpc_id
p_out_block.binary_blob = block_bytes
p_out_block.to_address = return_address
self.send_block_choke(p_out_block, return_address, 3)
time.sleep(0.002)
file_offset+=block_size
logging.debug('finished file transfer')
f.close()