encode/decode streams