ranch_transport.sendfile.asciidoc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. = ranch_transport:sendfile(3)
  2. == Name
  3. ranch_transport:sendfile - Send a file on the socket
  4. == Description
  5. [source,erlang]
  6. ----
  7. sendfile(Transport :: module(),
  8. Socket :: ranch_transport:socket(),
  9. File :: file:name_all() | file:fd(),
  10. Offset :: non_neg_integer(),
  11. Bytes :: non_neg_integer(),
  12. Opts :: ranch_transport:sendfile_opts())
  13. -> {ok, SentBytes :: non_neg_integer()} | {error, atom()}
  14. ----
  15. Send a file on the socket.
  16. The file may be sent full or in parts, and may be specified
  17. by its filename or by an already open file descriptor.
  18. This function emulates the function `file:sendfile/2,4,5`
  19. and may be used when transports are not manipulating TCP
  20. directly.
  21. == Arguments
  22. Transport::
  23. The transport module.
  24. Socket::
  25. The socket.
  26. File::
  27. The filename or file descriptor for the file to be sent.
  28. Offset::
  29. Start position in the file, in bytes.
  30. Bytes::
  31. Length in bytes.
  32. Opts::
  33. Additional options.
  34. == Return value
  35. The number of bytes actually sent is returned on success
  36. inside an `ok` tuple.
  37. An `error` tuple is returned otherwise.
  38. == Changelog
  39. * *1.6*: The type of the `File` argument was extended.
  40. == Examples
  41. .Implement Transport:sendfile using the fallback
  42. [source,erlang]
  43. ----
  44. sendfile(Socket, Filename) ->
  45. sendfile(Socket, Filename, 0, 0, []).
  46. sendfile(Socket, File, Offset, Bytes) ->
  47. sendfile(Socket, File, Offset, Bytes, []).
  48. sendfile(Socket, File, Offset, Bytes, Opts) ->
  49. ranch_transport:sendfile(?MODULE, Socket,
  50. File, Offset, Bytes, Opts).
  51. ----
  52. == See also
  53. link:man:ranch_transport(3)[ranch_transport(3)]