Add new utility function for encoding to libreaders