From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26273 invoked by alias); 24 Sep 2011 21:42:53 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 16424 Received: (qmail 21633 invoked from network); 24 Sep 2011 21:42:51 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <110924144246.ZM25537@torch.brasslantern.com> Date: Sat, 24 Sep 2011 14:42:46 -0700 In-reply-to: <1316895804.27230.YahooMailClassic@web65605.mail.ac4.yahoo.com> Comments: In reply to Guido van Steen "Re: pure zsh implementation of wget" (Sep 24, 1:23pm) References: <1316895804.27230.YahooMailClassic@web65605.mail.ac4.yahoo.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: pure zsh implementation of wget MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Sep 24, 1:23pm, Guido van Steen wrote: } } Now hopefully my last question: is there an easy way to get rid of the } first part of the file That's just the standard header in the HTTP format, like the header on an email message. You just have to discard everything up to the first blank line. One other thing you may want to do is switch from 'HTTP/1.1' to 1.0 to prevent the server from breaking the content into chunks. You'll be limited to 10MB downloads but won't have to interpret any content after the first blank line. A blank line here means one matching $'\015\012', but "read" will strip the $'\012' so: zwget() { emulate -LR zsh local scheme empty server resource fd headerline IFS=/ read scheme empty server resource <<<$1 case $scheme in (https:) print -u2 SSL unsupported, falling back on HTTP ;& (http:) zmodload zsh/net/tcp ztcp $server 80 && fd=$REPLY || return 1;; (*) print -u2 $scheme unsupported; return 1;; esac print -l -u$fd -- \ "GET /$resource HTTP/1.0"$'\015' \ "Host: $server"$'\015' \ 'Connection: close'$'\015' $'\015' while IFS= read -u $fd -r headerline do [[ $headerline == $'\015' ]] && break done while IFS= read -u $fd -r -e; do :; done ztcp -c $fd }