Encode content before write