Choose correct stream depending on output mode

We need a binary stream if we're writing in a binary format.

Contributes to issue CURA-5097.
This commit is contained in:
Ghostkeeper 2018-03-16 14:37:08 +01:00
parent e74191f2db
commit 5a5766f11a
No known key found for this signature in database
GPG key ID: 5252B696FB5E7C7A

View file

@ -7,7 +7,7 @@ from UM.Application import Application
from UM.Logger import Logger
from UM.Message import Message
from UM.FileHandler.WriteFileJob import WriteFileJob
from UM.Mesh.MeshWriter import MeshWriter
from UM.FileHandler.FileWriter import FileWriter #To check against the write modes (text vs. binary).
from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator
from UM.OutputDevice.OutputDevice import OutputDevice
from UM.OutputDevice import OutputDeviceError
@ -82,8 +82,11 @@ class RemovableDriveOutputDevice(OutputDevice):
try:
Logger.log("d", "Writing to %s", file_name)
# Using buffering greatly reduces the write time for many lines of gcode
if preferred_format["mode"] == FileWriter.OutputMode.TextMode:
self._stream = open(file_name, "wt", buffering = 1, encoding = "utf-8")
job = WriteFileJob(writer, self._stream, nodes, MeshWriter.OutputMode.TextMode)
else: #Binary mode.
self._stream = open(file_name, "wb", buffering = 1)
job = WriteFileJob(writer, self._stream, nodes, preferred_format["mode"])
job.setFileName(file_name)
job.progress.connect(self._onProgress)
job.finished.connect(self._onFinished)