From owner-freebsd-questions@FreeBSD.ORG Sun Aug 31 12:50:12 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CAF5716A4C1 for ; Sun, 31 Aug 2003 12:50:12 -0700 (PDT) Received: from mtaw4.prodigy.net (mtaw4.prodigy.net [64.164.98.52]) by mx1.FreeBSD.org (Postfix) with ESMTP id 56F5C43F93 for ; Sun, 31 Aug 2003 12:50:11 -0700 (PDT) (envelope-from mbsd@pacbell.net) Received: from atlas (adsl-64-160-45-240.dsl.snfc21.pacbell.net [64.160.45.240]) by mtaw4.prodigy.net (8.12.9/8.12.3) with ESMTP id h7VJo9fa012237; Sun, 31 Aug 2003 12:50:10 -0700 (PDT) Date: Sun, 31 Aug 2003 12:50:09 -0700 (PDT) From: =?ISO-8859-1?Q?Mikko_Ty=F6l=E4j=E4rvi?= X-X-Sender: mikko@atlas.home To: pbdlists@pinboard.com In-Reply-To: <20030831003205.A94657@pinboard.com> Message-ID: <20030831123819.V59430@atlas.home> References: <200308271100.42049.dkelly@HiWAAY.net> <20030829235939.GE42454@grumpy.dyndns.org> <3F50CF19.5030200@mac.com> <20030831003205.A94657@pinboard.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: FreeBSD-Questions@freebsd.org Subject: Re: zmore for bzip2? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 31 Aug 2003 19:50:12 -0000 On Sun, 31 Aug 2003 pbdlists@pinboard.com wrote: > Adapting zmore for the case where you specify the files to display on > the command line is not problem at all: > > > diff kk zmore > 5,14d4 > < get_decompressor () > < { > < case `file ${1--} | sed "s/[^:]*: *\([^ ]*\).*/\1/"` in > < "compress"*) DECOMPRESSOR="uncompress -c";; > < "gzip"*) DECOMPRESSOR="gzip -cdfq";; > < "bzip2"*) DECOMPRESSOR="bunzip2 -cdq";; > < *) DECOMPRESSOR="cat";; > < esac > < } > < > 56,57c46 > < get_decompressor ${FILE} > < ${DECOMPRESSOR} "$FILE" | eval ${PAGER-more} > --- > > gzip -cdfq "$FILE" | eval ${PAGER-more} > > But when zmore is used as a pipe or with input redirection, things become > more complicated. > > gzip -cdfq | eval ${PAGER-more} > > In order to detect the type of data passed on STDIN, the get_decompressor > function or any other means of detection would consume STDIN. STDIN, however > must be passed to the decompressor after the type of data has been > detected. I don't have an idea hot to 'duplicate' STDIN, so it could be As a somewhat ugly hack, you could read a few bytes, match against known magic numbers and then prepend those bytes to the stream before feeding to the decompressor, for the cost of an extra "cat" process: magic=$(dd bs=1 count=3 2>/dev/null) case $magic in BZh) DECOMPRESSOR=bunzip2;; *) DECOMPRESSOR="gzip -cdfq";; esac (echo -n "$magic"; exec cat) | $DECOMPRESSOR | eval ${PAGER-more} Note that gzip will handle compressed data and gzipped data as well as plain text. $.02, /Mikko > consumed twice. Sure, writing it to a temporary file would be a > workaround: > > 38,53c28 > < FILE="/tmp/.zmore.${$}" > < touch ${FILE} 2>/dev/null > < if [ "${?}" -ne "0" ]; then > < echo "can't create temporary file" > < exit 1 > < fi > < chmod 0600 ${FILE} > < cat >${FILE} > < if [ "${?}" -ne "0" ]; then > < echo "can't create temporary file" > < rm -f ${FILE} > < exit 1 > < fi > < get_decompressor ${FILE} > < cat ${FILE} | ${DECOMPRESSOR} | eval ${PAGER-more} > < rm -f ${FILE} > --- > > gzip -cdfq | eval ${PAGER-more} > > But I don't like that. I myself sometimes work with compressed files > larger than anything I would be happy to write to /tmp or somewhere else > (even though those cases usually rather use zcat and its cousinds than > zmore...) > > Kurt > > On Sat, Aug 30, 2003 at 12:21:45PM -0400, Chuck Swiger wrote: > > David Kelly wrote: > > [ ... ] > > > Yes, of course. But zmore is smart enough to figure out what to do with > > > several compression techniques, or even to handle non-compressed files > > > very trivially and without hassle. > > > > 'zmore' is a simple shell script which calls "gzcat | ${PAGER-more}". One > > solution to your problem, or at least a solution, would be to change zmore to > > look for a trailing bz/bz2 or invoke bzcat instead. Another would be to change > > the sources of gzip to recognize the bzip2 magic files bytes, extending the > > detection of gzip versus classic LZH used by compress. > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" >