Over the web service, I am returned an array of bytes. Part of which looks like the following… How do I get this back to a file? (It started as a pdf)
rg1uje94ppbarWm6azwlDCJeHFFJuXlMN532v46qiyi2u/WNVHCgl10DFe64oZVSFKHN7pZ6qaulNHULZJjix33PWhzPLBVwcbptx5Husx+a7Y4q3T76KBu7pfjvXeav1emibcBSG2mMFakTv0Ho7LvYsVf57hzUq8ptL752worpSKa3L0s9IJ6Z6qIlFzDaXW4ml+3WCWvaHhUW2H+6xfFSuhjHzL8pKmd5t3aI8vsun16YY1VwLw9ivAGX+GUPRVBOTYpVqgLikJhKB7Fkpn5SJSATFAQGoviYGsw7A+B2hA0dpVlisUf0mvC2LjYwfEhcUPGmvwG3sRpGJkUPtzXWx+5a2UaTOtytnLR9qwFbXKf8s2DxS9dR/p+/rwjb9mr24p7E2e8e/ZWNP7dpX7V7xJWpLAxu67lOYhixHFPRZff6063L5q8yGXtOc/J/YP5sSev6l8trGk+c+WNXSa5+b7PfpqY/WJbkefxp4Xe5RfaHqx6oqU/o9ObBdjn3MDm3MzkvFmrvWaXfPavC9s6/8gZZdMeI3cPyp8n/nBSnpjXYUwelZlyKm+ek7Pl8YfhXM4c6uTwxhPyJvZscfRnzaSd7cwWLTs3zj8ucXWe7TGzR+NGXumfk7HqVXCAkrJVS/T+uNDXKHSh5viMpPuTzW+vXu7vIj7eOXLT47XX1vYynzBdcaGx1qo0qrEijTL81UcSZRrFwS7Zv72L/paRvgswpPVdNKe/Qq9hT2R/XQXC8De/HaGVqkC1rkqFIxCto1vzFn1+1xGpOgu+fG/I7P7NBiqm+Ri823b7edVvMEvoIuVLjvjJ7Mv3nTRcV2ZKn+CeR06xqGtHnfN6XVCyyiRx8d2DdxbM0Whz19Imd928mSGz9KpLbXZ0NZhaNX7e08BjbR4fsO+fcdZ7fnhMz0FN2rEnplApbV+aLRt/zHFc15fDpt3/6Kz77vjM+aGNgjJ/eaCpseryirwPdcHuovZPLr3sVRnp2XZwpwH5hwrK0u3vB
Ive tried a few things, the closest is as follows (though I am unsure by the output if it is correct):
File.open(pdf_filename, 'w' ) do |output|
byteArray.each_byte do | byte |
output.print byte
puts byte
end
end
which returns in the console the following but does not create a valid file ( I assume these numbers are the bytes in Integer (base10)form or something?) :
77
52
79
89
57
etc..
I am no expert.. I am learning ruby myself at the moment (looking at questions on SO to vary techniques a bit 😉
but have you tried:
or maybe even (I really don’t know if that will work) I don’t have Ruby installed here to test:
I got this info from here (among other places):
http://strugglingwithruby.blogspot.com/2008/11/ruby-file-access.html
Depending on your byte array format, you may need to use the unpack method.
See the following for possible parameters in the unpack method:
http://www.codeweblog.com/ruby-string-pack-unpack-detailed-usage/