@@ -4134,7 +4134,11 @@ def _header(self) -> None:
41344134 def _write_file_length (self ) -> None :
41354135 # self.file required to be at correct position, e.g.
41364136 # if called by self._header
4137- self .file .write (pack (">i" , self ._shp_file_length_B ()))
4137+
4138+ # Calculate size as 16-bit words
4139+ size_B = self ._shp_file_length_B ()
4140+ size_16b_words = size_B // 2
4141+ self .file .write (pack (">i" , size_16b_words ))
41384142
41394143 def _shp_file_length_B (self ) -> int :
41404144 """Calculates the file length of the shp file."""
@@ -4143,9 +4147,7 @@ def _shp_file_length_B(self) -> int:
41434147
41444148 # Calculate size of all shapes
41454149 self .file .seek (0 , 2 )
4146- size_16b_words = self .file .tell ()
4147- # Calculate size as 16-bit words
4148- size_B = size_16b_words // 2
4150+ size_B = self .file .tell ()
41494151 # Return to start
41504152 self .file .seek (start_B )
41514153 return size_B
@@ -4199,7 +4201,7 @@ def shape(
41994201 self ,
42004202 s : Shape | HasGeoInterface | GeoJSONHomogeneousGeometryObject ,
42014203 ) -> tuple [int , int ]:
4202- """Returns shape's offset and length in B"""
4204+ """Appends s to the file. Returns shape's offset and length in B"""
42034205 if not isinstance (s , Shape ):
42044206 if isinstance (s , HasGeoInterface ):
42054207 shape_dict = s .__geo_interface__
@@ -4216,7 +4218,7 @@ def shape(
42164218 return self ._shp_record (s )
42174219
42184220 def _shp_record (self , s : Shape ) -> tuple [int , int ]:
4219- """Returns shape's offset and length in B"""
4221+ """Appends s to the file. Returns shape's offset and length in B"""
42204222 offset = self .file .tell ()
42214223 self .shpNum += 1
42224224
0 commit comments