[Haskell-cafe] Download binary file
kelanslists at gmail.com
Tue Nov 15 08:29:44 EST 2005
Using buffers to read and write from a Handle is pretty easy. You can
use 'allocaBytes' (from Foreign.Marshal.Alloc) to allocate the buffer
size you want, and a Ptr to that gets passed to the IO computation
that you give to allocaBytes as an argument. You can see a simplistic
example of network IO with buffers here:
In particular, the last function, 'requestLoop', uses a buffer to read
a specific number of bytes from a Handle on each iteration.
On 11/14/05, Jorge Guerra <jegd at ldc.usb.ve> wrote:
> Hi everyone,
> I'm trying to download a binary file (an mp3) from a given URL, at the
> moment I've found two possible solutions:
> 1) Use the Network.Socket library from ghc to get the file. The problem
> with this is that I'll have to deal with the HTTP protocol (done), and
> read the Handle in binary mode however I don't understand how to do
> this, in particular how to deal with the buffer (Prt?).
> 2) Use a system program like wget in linux systems. But I don't know
> how to call a system command from haskell, and besides I wan't my
> program to be portable at least between windows and linux.
> Any sugestions?
> Sorry for my newbie question.
> Jorge E. Guerra D.
> Departamento de Computación y Tecnología de la Información
> Universidad Simón Bolívar
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe