def replace_in_file(workspace, src_file_path, from_str, to_str):
  """Replace from_str with to_str in the name and content of the given file.

  If any edits were necessary, returns the new filename (which may be the same as the old filename).
  """
  from_bytes = from_str.encode('ascii')
  to_bytes = to_str.encode('ascii')
  data = read_file(os.path.join(workspace, src_file_path), binary_mode=True)
  if from_bytes not in data and from_str not in src_file_path:
    return None

  dst_file_path = src_file_path.replace(from_str, to_str)
  safe_file_dump(os.path.join(workspace, dst_file_path),
                 data.replace(from_bytes, to_bytes),
                 mode='wb')
  if src_file_path != dst_file_path:
    os.unlink(os.path.join(workspace, src_file_path))
  return dst_file_path
Replace from_str with to_str in the name and content of the given file.

  If any edits were necessary, returns the new filename (which may be the same as the old filename).