 			exports.rescanDrives(callback)
 
 		(callback) ->
+			deviceFileStream = fs.createWriteStream(devicePath, flags: DISK_IO_FLAGS)
+			deviceFileStream.on('error', callback)
+
+			imageFileStream = fs.createReadStream(imagePath)
 			imageFileStream
 				.pipe(progress)
 				.pipe(deviceFileStream)

progressStream = require('progress-stream')

IS_WINDOWS = os.platform() is 'win32'

exports.rescanDrives = (callback) ->
	return callback() if not IS_WINDOWS

	if not IS_WINDOWS and not fs.existsSync(devicePath)
		return callback(new Error("Invalid device: #{devicePath}"))

	imageFileSize = fs.statSync(imagePath).size

	if imageFileSize is 0
		return callback(new Error("Invalid OS image: #{imagePath}. The image is 0 bytes."))

	progress = progressStream
		length: imageFileSize
