#!/usr/bin/env perl # this script reads a squid cache file on stdin, prints a HTTP style # formatted header to stdout and dumps out the binary data on stderr. # meta is sent to stdout so it can easily be piped to other # programs. binary data is on stderr so it can easily be ignored by # routing stderr to /dev/null # TODO: # - globbing # - conditional binary dump # - find out how squid finds the files. (hash?) # first read with NULL terminator till we find the URL $/="\x00"; while (<>){ # URL found if (m/^http:/){ # convert NULL to newline and print with tag s/\x00/\n/s; print "URL: $_"; # from here on, records are separated by newlines $/="\n"; while (<>) { # skip until first header, which is assumed to be "Date: " if (m/^Date:/) { print; while (<>){ # empty line, dump the rest to STDOUT if (m/^\r\n/){ while (<>) { print STDERR $_; } } # continue printing header lines print; } } } } }