Allow setting encoding

Not sure if this is the best way, but something like it.
Could work. `ret` would still need to be an array for buffers though.