#NEWLINE# def Download( self , source_file , source_len = 0 , info_cb = DEFAULT_MESSAGE_CALLBACK , progress_callback = None ) : #NEWLINE# #INDENT# "Downloads a file to the device.\n\n    Args:\n      source_file: A filename or file-like object to download to the device.\n      source_len: Optional length of source_file. If source_file is a file-like\n          object and source_len is not provided, source_file is read into\n          memory.\n      info_cb: Optional callback accepting FastbootMessage for text sent from\n          the bootloader.\n      progress_callback: Optional callback called with the percent of the\n          source_file downloaded. Note, this doesn't include progress of the\n          actual flashing.\n\n    Returns:\n      Response to a download request, normally nothing.\n    " #NEWLINE# if isinstance ( source_file , basestring ) : #NEWLINE# #INDENT# source_len = os . stat ( source_file ) . st_size #NEWLINE# source_file = open ( source_file ) #NEWLINE# #UNINDENT# if ( source_len == 0 ) : #NEWLINE# #INDENT# data = source_file . read ( ) #NEWLINE# source_file = cStringIO . StringIO ( source_file ) #NEWLINE# source_len = len ( data ) #NEWLINE# #UNINDENT# self . _protocol . SendCommand ( 'download' , ( '%08x' % source_len ) ) #NEWLINE# return self . _protocol . HandleDataSending ( source_file , source_len , info_cb , progress_callback = progress_callback )