MCPcopy Index your code
hub / github.com/tinode/chat / fileDownload

Function fileDownload

tn-cli/commands.py:460–481  ·  view source on GitHub ↗
(id, cmd, args)

Source from the content-addressed store, hash-verified

458
459
460def fileDownload(id, cmd, args):
461 req = pb.FileDownReq(id=str(id), auth=pb.Auth(scheme='token', secret=tn_globals.AuthToken),
462 uri=cmd.filename, if_modified="")
463
464 # Call the server
465 stream = pbx.NodeStub(tn_globals.Connection).LargeFileServe(req)
466 # Read file chunks
467 fd = None
468 for chunk in stream:
469 if chunk:
470 if chunk.code >= 400:
471 stdoutln("Failed to download '{0}': {1} {2}".format(cmd.filename, chunk.code, chunk.text))
472 break
473 if chunk.code >= 300:
474 stdoutln("Use HTTP {0} to download from {1}".format(chunk.code, chunk.redir_url))
475 break
476 if not fd:
477 fd = open(chunk.meta.name, mode='wb')
478 fd.write(chunk.content)
479 continue
480 if fd:
481 fd.close()
482
483
484# Given an array of parts, parse commands and arguments

Callers

nothing calls this directly

Calls 2

stdoutlnFunction · 0.90
LargeFileServeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…