1 |
# |
2 |
# -*- Perl -*- |
3 |
# $Id: bzip2.pl,v 1.16 2000/03/23 10:41:04 knok Exp $ |
4 |
# Copyright (C) 2000 Namazu Project All rights reserved , |
5 |
# This is free software with ABSOLUTELY NO WARRANTY. |
6 |
# |
7 |
# This program is free software; you can redistribute it and/or modify |
8 |
# it under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either versions 2, or (at your option) |
10 |
# any later version. |
11 |
# |
12 |
# This program is distributed in the hope that it will be useful |
13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with this program; if not, write to the Free Software |
19 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
20 |
# 02111-1307, USA |
21 |
# |
22 |
# This file must be encoded in EUC-JP encoding |
23 |
# |
24 |
|
25 |
package bzip2; |
26 |
use strict; |
27 |
require 'util.pl'; |
28 |
|
29 |
my $bzip2path = undef; |
30 |
|
31 |
sub mediatype() { |
32 |
return ('application/x-bzip2'); |
33 |
} |
34 |
|
35 |
sub status() { |
36 |
$bzip2path = util::checkcmd('bzip2'); |
37 |
return 'no' unless (defined $bzip2path); |
38 |
return 'yes'; |
39 |
} |
40 |
|
41 |
sub recursive() { |
42 |
return 1; |
43 |
} |
44 |
|
45 |
sub pre_codeconv() { |
46 |
return 0; |
47 |
} |
48 |
|
49 |
sub post_codeconv () { |
50 |
return 0; |
51 |
} |
52 |
|
53 |
sub add_magic ($) { |
54 |
return; |
55 |
} |
56 |
|
57 |
sub filter ($$$$$) { |
58 |
my ($orig_cfile, $cont, $weighted_str, $headings, $fields) |
59 |
= @_; |
60 |
|
61 |
my $tmpfile = util::tmpnam('NMZ.bzip2'); |
62 |
|
63 |
util::vprint("Processing bzip2 file ... (using '$bzip2path')\n"); |
64 |
|
65 |
{ |
66 |
my $fh = util::efopen("|$bzip2path -d > $tmpfile"); |
67 |
print $fh $$cont; |
68 |
} |
69 |
{ |
70 |
my $fh = util::efopen("$tmpfile"); |
71 |
my $size = util::filesize($fh); |
72 |
if ($size > $conf::FILE_SIZE_MAX) { |
73 |
return 'too_large_gzipped_file'; |
74 |
} |
75 |
$$cont = util::readfile($fh); |
76 |
} |
77 |
unlink($tmpfile); |
78 |
return undef; |
79 |
} |
80 |
|
81 |
1; |