Shorter, simler, faster! Use IO.copy_stream to stream files to the socket.