backport binwrite from Ruby 2.1+