code: def GetSortedEvents(self, time_range=None):
      
      if not self._is_open:
        raise IOError('Unable to read from closed storage writer.')
  
      event_heap = event_heaps.EventHeap()
  
      for event in self._events:
        if (time_range and (
            event.timestamp < time_range.start_timestamp or
            event.timestamp > time_range.end_timestamp)):
          continue
  
        # Make a copy of the event before adding the event data.
        event = copy.deepcopy(event)
        # TODO: refactor this into psort.
        self._ReadEventDataIntoEvent(event)
  
        event_heap.PushEvent(event)
  
      return iter(event_heap.PopEvents())
docs: Retrieves the events in increasing chronological order.
  
      Args:
        time_range (Optional[TimeRange]): time range used to filter events
            that fall in a specific period.
  
      Returns:
        generator(EventObject): event generator.
  
      Raises:
        IOError: when the storage writer is closed.
        OSError: when the storage writer is closed.