File: Gzip.pm

package info (click to toggle)
tiarra 20100212-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,732 kB
  • ctags: 1,712
  • sloc: perl: 32,032; lisp: 193; sh: 109; makefile: 10
file content (76 lines) | stat: -rw-r--r-- 2,063 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- cperl -*-
# -----------------------------------------------------------------------------
# $Id: Gzip.pm 3004 2007-12-10 12:45:39Z topia $
# -----------------------------------------------------------------------------
# copyright (C) 2003 Topia <topia@clovery.jp>. all rights reserved.
package System::Inflate::Gzip;
use strict;
use warnings;
use Carp;
use base qw(System::Inflate::Zlib);

sub new {
  my ($obj) = $_[0]->SUPER::new(@_);

  $obj->{accept} = 'gzip';

  return $obj;
}

sub setup {
  my ($this, $parent) = @_;

  foreach my $compressor qw(gzip) {
    $parent->{compressor}->{$compressor} = $this;
    $this->{parent} = $parent;
  }

  return $parent;
}

sub init {
  my ($this, $datas, $data_chunk) = @_;
  my $ret = $this->SUPER::init($datas, $data_chunk);

  if ($ret == $this->parent->COMP_OK) {
    $datas->{data} = 
      {
       crc32 => undef,
       len => undef,
       data_len => 0,
       data_crc32 => undef,
      };
    $datas->{lasterr} = Compress::Zlib::_removeGzipHeader($data_chunk);
    return undef if $datas->{lasterr} != $this->{Z_OK};
    return $this->parent->COMP_OK if $datas->{lasterr} == $this->{Z_OK};
    return $this->parent->COMP_OTHER_ERR;
  } else {
    return $ret;
  }
}

sub inflate {
  my ($this, $datas, $data_chunk) = @_;
  my ($ret, $err);

  ($ret, $err) = $this->SUPER::inflate($datas, $data_chunk);

  $datas->{data}->{data_len} += length($ret);
  $datas->{data}->{data_crc32} = Compress::Zlib::crc32($ret, $datas->{data}->{data_crc32});
  if ($datas->{lasterr} == $this->{Z_STREAM_END}) {
    ($datas->{data}->{crc32}, $datas->{data}->{len}) = unpack ("VV", substr($$data_chunk, 0, 8));
    substr($$data_chunk, 0, 8) = '';
  }
  return ($ret, $err);
}

sub check {
  my ($this, $datas) = @_;
  my ($compdata) = $datas->{data};

  return undef unless defined($compdata->{len}) && defined($compdata->{crc32});
  return $this->parent->COMP_DATA_ERROR unless 
    ($compdata->{len} == $compdata->{data_len}) && ($compdata->{crc32} == $compdata->{data_crc32});
  return $this->parent->COMP_OK;
}
1;