hMatoba / Piexif

Exif manipulation with pure python script.
MIT License
367 stars 81 forks source link

Better struct module usage #128

Open homm opened 2 years ago

homm commented 2 years ago

This improves usage of standard struct module. unpack_from function doesn't require extra copying as well as doesn't require data length match.

Also there was a several places where sequence of unpack calls can be replaced with single call.

-            tag = struct.unpack(self.endian_mark + "H",
-                       self.tiftag[pointer: pointer+2])[0]
-            value_type = struct.unpack(self.endian_mark + "H",
-                         self.tiftag[pointer + 2: pointer + 4])[0]
-            value_num = struct.unpack(self.endian_mark + "L",
-                                      self.tiftag[pointer + 4: pointer + 8]
-                                      )[0]
+            tag, value_type, value_num = unpack_from(
+                self.endian_mark + "HHL", self.tiftag, pointer)