code: def check(self, metainfo, datapath, progress=None):
          
          if datapath:
              self.datapath = datapath
  
          def check_piece(filename, piece):
              "Callback for new piece"
              if piece != metainfo["info"]["pieces"][check_piece.piece_index:check_piece.piece_index+20]:
                  self.LOG.warn("Piece #%d: Hashes differ in file %r" % (check_piece.piece_index//20, filename))
              check_piece.piece_index += 20
          check_piece.piece_index = 0
  
          datameta, _ = self._make_info(int(metainfo["info"]["piece length"]), progress,
              [datapath] if "length" in metainfo["info"] else
              (os.path.join(*([datapath] + i["path"])) for i in metainfo["info"]["files"]),
              piece_callback=check_piece
          )
          return datameta["pieces"] == metainfo["info"]["pieces"]
docs: Check piece hashes of a metafile against the given datapath.