code: def bz2_compress_stream(src, level=9):
      
      compressor = bz2.BZ2Compressor(level)
      for block in src:
          encoded = compressor.compress(block)
          if encoded:
              yield encoded
      yield compressor.flush()
docs: Compress data from `src`.
  
      Args:
          src (iterable): iterable that yields blocks of data to compress
          level (int): compression level (1-9) default is 9
  
      Yields:
          blocks of compressed data