encode directly from io streams