I have a piece of Ruby code that grabs a zip file from S3 and saves it locally.
File.open(local_filename, 'wb') { |file| file.write(body) }
This code works on some files but not others.
For the ones that don't work I get this error:
Errno::EINVAL: Invalid argument @ io_write - /path/to/file.zip
What could be the reason for this?
The body might be too huge. The error message indeed doesn't make much sense, but it's a possible cause.
To mitigate this, write it in smaller chunks. The simplest (though not the fastest) way is going character by character:
File.open('file_name.txt', 'wb') do |file|
body.each_char { |char| file.write char }
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With