Download the "head" of a large file?

Ben Charrow bcharrow at csail.mit.edu
Tue Jul 28 02:18:37 EDT 2009


Dennis Lee Bieber wrote:
> On Mon, 27 Jul 2009 13:38:25 -0700 (PDT), erikcw
> <erikwickstrom at gmail.com> declaimed the following in
> gmane.comp.python.general:
>> Something like the Python equivalent of curl http://url.com/file.xml |
>> head -c 2048
>>
> 	Presuming that | is a shell pipe operation, then doesn't that
> command line use "curl" to download the entire file, and "head" to
> display just the first 2k?

No, the entire file is not downloaded.  My understanding of why this is (which 
could be wrong) is that the output of curl is piped to head, and once head gets 
the first 2k it closes the pipe.  Then, when curl tries to write to the pipe 
again, it gets sent the SIGPIPE signal at which point it exits.

Cheers,
Ben



More information about the Python-list mailing list