add stream write function