Skip to content

Commit

Permalink
utils/classic: add variable chunk size support for download & upload
Browse files Browse the repository at this point in the history
  • Loading branch information
fab committed Aug 11, 2010
1 parent bca640b commit a28b882
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions utils/classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

SERVER_FILE = os.path.join(os.path.dirname(rpyc.__file__), "servers", "classic_server.py")
DEFAULT_SERVER_PORT = 18812
CHUNK_SIZE = 16000


#===============================================================================
Expand Down Expand Up @@ -50,6 +51,12 @@ def connect_thread():
#===============================================================================
# remoting utilities
#===============================================================================

def set_chunks_size(sz):
"""Sets the internal chunk size used for download & upload"""
global CHUNK_SIZE
CHUNK_SIZE = sz

def upload(conn, localpath, remotepath, filter = None, ignore_invalid = False):
"""uploads a file or a directory to the given remote path
localpath - the local file or directory
Expand All @@ -68,7 +75,7 @@ def upload_file(conn, localpath, remotepath):
lf = open(localpath, "rb")
rf = conn.modules.__builtin__.open(remotepath, "wb")
while True:
buf = lf.read(16000)
buf = lf.read(CHUNK_SIZE)
if not buf:
break
rf.write(buf)
Expand Down Expand Up @@ -102,7 +109,7 @@ def download_file(conn, remotepath, localpath):
rf = conn.modules.__builtin__.open(remotepath, "rb")
lf = open(localpath, "wb")
while True:
buf = rf.read(16000)
buf = rf.read(CHUNK_SIZE)
if not buf:
break
lf.write(buf)
Expand Down

0 comments on commit a28b882

Please sign in to comment.