Hello, I'm having a lot of trouble sending binary files through a socket (I'm trying to program a very minimalistic webserver) but I just can't find a way to read and send binary files, even though, plain text and html documents are sent correctly.<br>
<br>My code looks something like this:<br><br>sendResource handle name = <br> do exist <- doesFileExist name <br> isFile <- liftM not (doesDirectoryExist name)<br> if exist && isFile <br> then do resource <- Data.ByteString.readFile name<br>
hPutStr handle (header ++ fileType ++ "\n") <br> hSetBinaryMode handle True<br> hPutStr handle resource<br> else do hPutStr handle page404<br> where fileType = maybe ("text/plain") (flip const []) <br>
(lookup (takeExtension name) extensions)<br><br>Thanks for your help in advance.<br><br>PS: Yes, I'm terribly newbie to Haskell.<br>