-def extract_image(device, outfile, size):
- blocksize = 4194304 # 4MB
- progress_size = (size + 1048575) // 1048576 # in MB
- progressbar = progress_generator("Dumping image file: ",
- progress_size)
- source = open(device, "r")
- try:
- dest = open(outfile, "w")
- try:
- left = size
- offset = 0
- progressbar.next()
- while left > 0:
- length = min(left, blocksize)
- sent = sendfile(dest.fileno(), source.fileno(), offset, length)
- offset += sent
- left -= sent
- for i in range(4):
- progressbar.next()
- finally:
- dest.close()
- finally:
- source.close()
-
- success('Image file %s was successfully created' % outfile)
-
-