Cura/plugins/GCodeGzReader/GCodeGzReader.py
Diego Prado Gesto dd0d0d20e9 CURA-5128 Modify the GCode parser to use a stream instead of a file so
we can reuse methods for the GCodeGZReader.
2018-03-23 17:14:53 +01:00

27 lines
955 B
Python

# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
import gzip
from io import TextIOWrapper
from UM.Mesh.MeshReader import MeshReader #The class we're extending/implementing.
from UM.PluginRegistry import PluginRegistry
## A file writer that writes gzipped g-code.
#
# If you're zipping g-code, you might as well use gzip!
class GCodeGzReader(MeshReader):
def __init__(self):
super(GCodeGzReader, self).__init__()
self._supported_extensions = [".gcode.gz"]
def read(self, file_name):
with open(file_name, "rb") as file:
file_data = file.read()
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