GCodeGzReader.py 931 B

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