GCodeGzReader.py 935 B

123456789101112131415161718192021222324252627
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import gzip
  4. from io import TextIOWrapper
  5. from UM.Mesh.MeshReader import MeshReader #The class we're extending/implementing.
  6. from UM.PluginRegistry import PluginRegistry
  7. ## A file reader that reads gzipped g-code.
  8. #
  9. # If you're zipping g-code, you might as well use gzip!
  10. class GCodeGzReader(MeshReader):
  11. def __init__(self):
  12. super().__init__()
  13. self._supported_extensions = [".gcode.gz"]
  14. def read(self, file_name):
  15. with open(file_name, "rb") as file:
  16. file_data = file.read()
  17. uncompressed_gcode = gzip.decompress(file_data).decode("utf-8")
  18. PluginRegistry.getInstance().getPluginObject("GCodeReader").preReadFromStream(uncompressed_gcode)
  19. result = PluginRegistry.getInstance().getPluginObject("GCodeReader").readFromStream(uncompressed_gcode)
  20. return result