sendfile-0.4: A portable sendfile librarySource codeContentsIndex
Network.Socket.SendFile
Contents
Safe functions (recommended)
Unsafe functions (not recommended)
Utility functions
Description

A cross-platform wrapper for sendfile -- this implements an available operating-system call if supported, otherwise it falls back to a portable haskell implementation.

Two interfaces are provided for both the unsafe and safe sets of functions. The first interface accepts an output socket/handle and the path of the file you want to send; sendFile and unsafeSendFile comprise this interface. The second interface accepts an output socket/handle, a handle to the file you want to send, and the number of bytes you want to send; sendFile' and unsafeSendFile' comprise this interface.

For consistent read/write behavior with either sendFile' or unsafeSendFile', the input handle should be opened in Binary mode rather than Text mode (especially if you are using hSeek before sending).

Synopsis
sendFile :: Socket -> FilePath -> IO ()
sendFile' :: Socket -> Handle -> Integer -> IO ()
unsafeSendFile :: Handle -> FilePath -> IO ()
unsafeSendFile' :: Handle -> Handle -> Integer -> IO ()
sendFileMode :: String
Safe functions (recommended)
sendFileSource
:: SocketThe output socket
-> FilePathThe path where the input file resides
-> IO ()
The simplest interface. Simply give it an output Socket and the FilePath to the input file.
sendFile'Source
:: SocketThe output socket
-> HandleThe input file handle
-> IntegerThe number of bytes to send
-> IO ()
A more powerful interface than sendFile, sendFile' accepts a Handle for the input file instead of a FilePath and the number of bytes you would like to read; this number must be a positive integer. This unlocks the full potential Handle(s). For instance, if you wanted to start reading from a particular offset in the file you could utilize hSeek; if you needed the file size you could use hFileSize.
Unsafe functions (not recommended)

With unsafeSendFile and unsafeSendFile' the output should only be a Handle derived from a network socket (by using socketToHandle). These functions are unsafe because you cannot know whether or not a Handle is actually a Socket at compile-time. If you try to use a Handle for the output which is not in fact a socket, you will get a runtime error.

These functions are provided for convenience given that the current high-level interface in the Network package gives you a Handle when you use accept. They may be deprecated in the future.

unsafeSendFileSource
:: HandleThe output handle
-> FilePathThe path where the input file resides
-> IO ()
The unsafe version of sendFile which accepts a Handle instead of a Socket for the output. It will flush the output handle before sending any file data.
unsafeSendFile'Source
:: HandleThe output handle
-> HandleThe input file handle
-> IntegerThe number of bytes to send
-> IO ()
The unsafe version of sendFile' which accepts a Handle instead of a Socket for the output. It will flush the output handle before sending any file data.
Utility functions
sendFileModeSource
:: StringThe mode that sendfile was compiled with
Returns the mode that sendfile was compiled with. Mainly for debugging use. Possible values are WIN32_SENDFILE, LINUX_SENDFILE, FREEBSD_SENDFILE, and PORTABLE_SENDFILE.
Produced by Haddock version 2.4.2