accepts stream or null