Fix joyent/node#8683

This PR fixed the encoding issue of converting external string into Buffer (#8683).
I don't know how to compute the length correctly for each encoding. But creating a temporary string is the simplest way to fix this issue.