I didn't know about `#valid_encoding`, neat!  This should be a lot faster than a `begin ...  rescue ... end ` block.