abstract stream to buffer