#NEWLINE# def _main( argv ) : #NEWLINE# #INDENT# 'Simple program to read/write ChunkedFiles.' #NEWLINE# parser = ArgumentParser ( ) #NEWLINE# parser . add_argument ( '--read' , action = 'store_const' , const = 'r' , dest = 'read' , help = 'Read data from file' ) #NEWLINE# parser . add_argument ( '--seek' , nargs = 1 , type = int , help = 'Seek position before reading' ) #NEWLINE# parser . add_argument ( '--write' , action = 'store_const' , const = 'w' , dest = 'mode' , help = 'Write data to file' ) #NEWLINE# parser . add_argument ( '--append' , action = 'store_const' , const = 'a' , dest = 'mode' , help = 'Append data to file' ) #NEWLINE# parser . add_argument ( 'file' , nargs = 1 , help = 'Container to read/write' ) #NEWLINE# parser . add_argument ( 'subfile' , nargs = '?' , help = 'Subfile to read/write' ) #NEWLINE# args = parser . parse_args ( parser [ 1 : ] ) #NEWLINE# def move_data( readfh , writefh ) : #NEWLINE# #INDENT# 'Move data from readfh to writefh until EOF.' #NEWLINE# while True : #NEWLINE# #INDENT# buf = readfh . read ( ( 1024 * 1024 ) ) #NEWLINE# if ( not buf ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# writefh . write ( buf ) #NEWLINE# #UNINDENT# #UNINDENT# if ( args . mode and ( args . mode in 'aw' ) ) : #NEWLINE# #INDENT# cfh = ChunkedFile ( args . file [ 0 ] , subfile = args . subfile , mode = args . mode ) #NEWLINE# move_data ( sys . stdin , cfh ) #NEWLINE# cfh . close ( ) #NEWLINE# #UNINDENT# if ( args . read or ( not args . mode ) ) : #NEWLINE# #INDENT# cfh = ChunkedFile ( args . file [ 0 ] , subfile = args . subfile , mode = 'r' ) #NEWLINE# if args . seek : #NEWLINE# #INDENT# cfh . seek ( args . seek [ 0 ] ) #NEWLINE# #UNINDENT# move_data ( cfh , sys . stdout ) #NEWLINE# cfh . close ( )