phoenixframework/phoenix — pull request #512 by jlwebster (2014-12-06 19:09:05+00:00)
Title: Added ability for Phoenix.Channel to send binary data to the client (i.e. not wrapped in the usual %Message{} JSON)

The reason for this is if you wish to send back a binary file to the client, over the web socket connection, such as the following example use case:

The client sends an "image" event to the channel with a specific image_id. In response, the server sends back the binary of the image.

```Elixir
defmodule MyApp.MyChannel do
use Phoenix.Channel

...

def event(socket, "image", %{"image_id" => image_id}) do
{:ok, image_file} = File.open("/path/to/image/with/#{image_id}", [:read])
image_data = IO.binread(image_file, :all)
reply socket, image_data
socket
end

...

end
```

The binary opcode, instead of text, is set in the web socket response frame in cowboy for this type of response

Let me know your thoughts. Should I be discussing this on the phoenix-core list? I'm fairly new to phoenix and elixir, so I appreciate your patience. :-)