Fixed a bug which causes problem when RPC body size is bigger than 4096

- Fetching blobs (size>4k) works now
  - Updated the image fetching code in examples/test_client.py
This commit is contained in:
Cheng Guo 2018-05-06 14:55:00 +02:00 committed by Pedro Ferreira
parent 734fe59663
commit b26b56632f
2 changed files with 10 additions and 8 deletions

View File

@ -47,13 +47,13 @@ async def test_client():
handler.send(True, end=True)
break
"""
# TODO: save this blob, first.
async for data in api.call('blobs.get', ['&/6q7JOKythgnnzoBI5xxvotCr5HeFkAIZSAuqHiZfLw=.sha256'], 'source'):
if data.type.name == 'BUFFER':
with open('./funny_img.png', 'wb') as f:
f.write(data.data)
"""
img_data = b''
async for msg in api.call('blobs.get', ['&H4MFPEWh7gAbZG/4TaSsaJI6Hi8lh7PItrHTnaxoSfg=.sha256'], 'source'):
if msg.type.name == 'BUFFER':
img_data += msg.data
if msg.type.name == 'JSON' and msg.data == b'true':
with open('./Autonomouscar1956.jpg', 'wb') as f:
f.write(img_data)
async def main():

View File

@ -3,6 +3,7 @@ import struct
from asyncio import Event, Queue
from enum import Enum
from time import time
from math import ceil
import simplejson
from async_generator import async_generator, yield_
@ -134,8 +135,9 @@ class PacketStream(object):
if not header or header == b'\x00' * 9:
return
flags, length, req = struct.unpack('>BIi', header)
logger.debug('flags=%s length=%s req=%s', flags, length, req)
n_packets = length // 4096 + 1
n_packets = ceil(length / 4096)
body = b''
for n in range(n_packets):