* Added German translation, provided by Manfred Herrmann.
[BackupPC.git] / bin / BackupPC_zcat
1 #!/bin/perl -T
2 #============================================================= -*-perl-*-
3 #
4 # BackupPC_zcat: uncompress files to stdout
5 #
6 # DESCRIPTION
7 #
8 #   Usage: BackupPC_zcat [files...]
9 #
10 #   BackupPC_zcat is a command-line utility for uncompressing BackupPC
11 #   compressed files.
12 #
13 # AUTHOR
14 #   Craig Barratt  <cbarratt@users.sourceforge.net>
15 #
16 # COPYRIGHT
17 #   Copyright (C) 2001  Craig Barratt
18 #
19 #   This program is free software; you can redistribute it and/or modify
20 #   it under the terms of the GNU General Public License as published by
21 #   the Free Software Foundation; either version 2 of the License, or
22 #   (at your option) any later version.
23 #
24 #   This program is distributed in the hope that it will be useful,
25 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
26 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27 #   GNU General Public License for more details.
28 #
29 #   You should have received a copy of the GNU General Public License
30 #   along with this program; if not, write to the Free Software
31 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
32 #
33 #========================================================================
34 #
35 # Version 2.0.0beta1, released 30 Mar 2003.
36 #
37 # See http://backuppc.sourceforge.net.
38 #
39 #========================================================================
40
41 use strict;
42
43 use lib "/usr/local/BackupPC/lib";
44 use Compress::Zlib;
45 use BackupPC::FileZIO;
46
47 sub zcat
48 {
49     my($fh, $fileName) = @_;
50     my($data, $r);
51
52     while ( ($r = $fh->read(\$data, 65536)) > 0 ) { 
53         print($data);
54     }
55     if ( $r < 0 ) {
56         print(STDERR "$0: can't uncompress $fileName\n");
57     }
58     $fh->close();
59 }
60
61 if ( @ARGV ) {
62     while ( @ARGV ) {
63         if ( defined(my $fh = BackupPC::FileZIO->open($ARGV[0], 0, 1)) ) {
64             zcat($fh, $ARGV[0]);
65         } else {
66             print(STDERR "$0: can't open $ARGV[0]\n");
67             exit(1);
68         }
69         shift @ARGV;
70     }
71 } else {
72     my $fh = BackupPC::FileZIO->open(*STDIN, 0, 1);
73     zcat($fh, "stdin");
74 }