MCPcopy
hub / github.com/tinode/chat / iter_file

Function iter_file

tn-cli/commands.py:433–447  ·  view source on GitHub ↗
(filepath, size=1024*1024)

Source from the content-addressed store, hash-verified

431
432def fileUpload(id, cmd, args):
433 def iter_file(filepath, size=1024*1024):
434 _, name = os.path.split(filepath)
435 mimeType = mimetypes.guess_type(filepath)[0]
436 with open(filepath, mode='rb') as fd:
437 try:
438 yield pb.FileUpReq(id=str(id), auth=pb.Auth(scheme='token', secret=tn_globals.AuthToken),
439 topic="", meta=pb.FileMeta(name=name, mime_type=mimeType, size=0))
440 while True:
441 chunk = fd.read(size)
442 if chunk:
443 yield pb.FileUpReq(content=chunk)
444 else: # Finished.
445 break
446 except Exception as ex:
447 stdoutln("Failed to read '{0}':".format(cmd.filename), ex)
448
449 try:
450 response = pbx.NodeStub(tn_globals.Connection).LargeFileReceive(iter_file(cmd.filename))

Callers 1

fileUploadFunction · 0.85

Calls 1

stdoutlnFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…