docstr: Efficiently read all data needed (but scans all index)
code: def read_chunks(self, maxlen, buf):
      """Efficiently read all data needed (but scans all index)"""
      gens = []
      chunks = list(self._count_all_chunks())
      # chunks: [(0, 1024), (1, 1024), ..., (n, 1024)]
      chunks.reverse()
      remain = maxlen
      for gen, count in chunks:
          if maxlen is None:
              gens.append(gen)
          elif remain > 0:
              gens.append(gen)
              remain -= count
          else:
              break
      # gens: [n, n-1, ..., m]
      gens.reverse()
      for gen in gens:
          buf.extend(obj for obj in self.read_chunk(gen))
  
      gen = max(gens) + 1 if gens else 0
      return gen
  
imports: import binascii
  import collections
  import os
  import pickle
  from datetime import datetime
  from struct import calcsize, pack, unpack
  from pfrl.collections.random_access_queue import RandomAccessQueue
label_desc: Use image node_id 5 for calling the _ChunkReader obj's underlying member method code with example usage: obj.read_chunks(maxlen, buf) and returns: gen