mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
CURA-5128 Modify the GCode parser to use a stream instead of a file so
we can reuse methods for the GCodeGZReader.
This commit is contained in:
parent
c2888529cb
commit
dd0d0d20e9
4 changed files with 135 additions and 131 deletions
|
@ -2,15 +2,11 @@
|
|||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
import gzip
|
||||
import tempfile
|
||||
|
||||
from io import StringIO, BufferedIOBase #To write the g-code to a temporary buffer, and for typing.
|
||||
from typing import List
|
||||
from io import TextIOWrapper
|
||||
|
||||
from UM.Logger import Logger
|
||||
from UM.Mesh.MeshReader import MeshReader #The class we're extending/implementing.
|
||||
from UM.PluginRegistry import PluginRegistry
|
||||
from UM.Scene.SceneNode import SceneNode #For typing.
|
||||
|
||||
## A file writer that writes gzipped g-code.
|
||||
#
|
||||
|
@ -24,10 +20,8 @@ class GCodeGzReader(MeshReader):
|
|||
def read(self, file_name):
|
||||
with open(file_name, "rb") as file:
|
||||
file_data = file.read()
|
||||
uncompressed_gcode = gzip.decompress(file_data)
|
||||
with tempfile.NamedTemporaryFile() as temp_file:
|
||||
temp_file.write(uncompressed_gcode)
|
||||
PluginRegistry.getInstance().getPluginObject("GCodeReader").preRead(temp_file.name)
|
||||
result = PluginRegistry.getInstance().getPluginObject("GCodeReader").read(temp_file.name)
|
||||
uncompressed_gcode = gzip.decompress(file_data).decode("utf-8")
|
||||
PluginRegistry.getInstance().getPluginObject("GCodeReader").preReadFromStream(uncompressed_gcode)
|
||||
result = PluginRegistry.getInstance().getPluginObject("GCodeReader").readFromStream(uncompressed_gcode)
|
||||
|
||||
return result
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue