Skip to content

Instantly share code, notes, and snippets.

@VEINHORN
Last active August 29, 2015 14:13
Show Gist options
  • Save VEINHORN/f04214cb11c2c1749752 to your computer and use it in GitHub Desktop.
Save VEINHORN/f04214cb11c2c1749752 to your computer and use it in GitHub Desktop.
iodevice = file:open("client/" ++ Filename, [read, binary])
send_file_binary(Socket, IoDevice, Offset) ->
case file:pread(IoDevice, Offset, 1000) of
{ok, Data} ->
io:format("~B bytes sent.", [Offset + 1000]),
gen_tcp:send(Socket, <<1:32/integer, Data/binary>>),
send_file_binary(Socket, IoDevice, Offset + 1000);
eof ->
io:format("File sent."),
gen_tcp:send(Socket, <<2:32/integer>>) % 2 - uploading is done
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment