#NEWLINE# def downloadFile( self , file , offset = 0 , headers = True , endByte = None , contentDisposition = None , **kwargs ) : #NEWLINE# #INDENT# if ( ( endByte is None ) or ( endByte > file [ 'size' ] ) ) : #NEWLINE# #INDENT# endByte = file [ 'size' ] #NEWLINE# #UNINDENT# if headers : #NEWLINE# #INDENT# cherrypy . response . headers [ 'Accept-Ranges' ] = 'bytes' #NEWLINE# self . setContentHeaders ( file , offset , endByte , contentDisposition ) #NEWLINE# #UNINDENT# if file [ 'hdfs' ] . get ( 'imported' ) : #NEWLINE# #INDENT# path = file [ 'hdfs' ] [ 'path' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# path = self . _absPath ( file ) #NEWLINE# #UNINDENT# def stream( ) : #NEWLINE# #INDENT# position = 0 #NEWLINE# fileStream = self . client . cat ( [ path ] ) . next ( ) #NEWLINE# shouldBreak = False #NEWLINE# for chunk in fileStream : #NEWLINE# #INDENT# chunkLen = len ( chunk ) #NEWLINE# if ( position < offset ) : #NEWLINE# #INDENT# if ( ( position + chunkLen ) > offset ) : #NEWLINE# #INDENT# if ( ( position + chunkLen ) > endByte ) : #NEWLINE# #INDENT# chunkLen = ( endByte - position ) #NEWLINE# shouldBreak = True #NEWLINE# #UNINDENT# ( yield chunk [ ( offset - position ) : chunkLen ] ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( position + chunkLen ) > endByte ) : #NEWLINE# #INDENT# chunkLen = ( endByte - position ) #NEWLINE# shouldBreak = True #NEWLINE# #UNINDENT# ( yield chunk [ : chunkLen ] ) #NEWLINE# #UNINDENT# position += chunkLen #NEWLINE# if shouldBreak : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return stream