Date: Sun, 31 Aug 2003 00:32:05 +0200 From: pbdlists@pinboard.com To: FreeBSD-Questions@freebsd.org Subject: Re: zmore for bzip2? Message-ID: <20030831003205.A94657@pinboard.com> In-Reply-To: <3F50CF19.5030200@mac.com>; from cswiger@mac.com on Sat, Aug 30, 2003 at 12:21:45PM -0400 References: <200308271100.42049.dkelly@HiWAAY.net> <20030828043747.GA1206@terminator.client.attbi.com> <20030829235939.GE42454@grumpy.dyndns.org> <3F50CF19.5030200@mac.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030831003205.A94657>