code: def __dbfHeader(self):
          
          if not self.dbf:
              raise ShapefileException("Shapefile Reader requires a shapefile or file-like object. (no dbf file found)")
          dbf = self.dbf
          # read relevant header parts
          self.numRecords, self.__dbfHdrLength, self.__recordLength = \
                  unpack("<xxxxLHH20x", dbf.read(32))
          # read fields
          numFields = (self.__dbfHdrLength - 33) // 32
          for field in range(numFields):
              fieldDesc = list(unpack("<11sc4xBB14x", dbf.read(32)))
              name = 0
              idx = 0
              if b"\x00" in fieldDesc[name]:
                  idx = fieldDesc[name].index(b"\x00")
              else:
                  idx = len(fieldDesc[name]) - 1
              fieldDesc[name] = fieldDesc[name][:idx]
              fieldDesc[name] = u(fieldDesc[name], self.encoding, self.encodingErrors)
              fieldDesc[name] = fieldDesc[name].lstrip()
              fieldDesc[1] = u(fieldDesc[1], 'ascii')
              self.fields.append(fieldDesc)
          terminator = dbf.read(1)
          if terminator != b"\r":
              raise ShapefileException("Shapefile dbf header lacks expected terminator. (likely corrupt?)")
          self.fields.insert(0, ('DeletionFlag', 'C', 1, 0))
          fmt,fmtSize = self.__recordFmt()
          self.__recStruct = Struct(fmt)
  
          # Store the field positions
          self.__fieldposition_lookup = dict((f[0], i) for i, f in enumerate(self.fields[1:]))
docs: Reads a dbf header. Xbase-related code borrows heavily from ActiveState Python Cookbook Recipe 362715 by Raymond Hettinger