xref: /openbsd-src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Gzip/Constants.pm (revision 3d61058aa5c692477b6d18acfbbdb653a9930ff9)
1b39c5158Smillertpackage IO::Compress::Gzip::Constants;
2b39c5158Smillert
3b39c5158Smillertuse strict ;
4b39c5158Smillertuse warnings;
5b39c5158Smillertuse bytes;
6b39c5158Smillert
7b39c5158Smillertrequire Exporter;
8b39c5158Smillert
9b39c5158Smillertour ($VERSION, @ISA, @EXPORT, %GZIP_OS_Names);
10b39c5158Smillertour ($GZIP_FNAME_INVALID_CHAR_RE, $GZIP_FCOMMENT_INVALID_CHAR_RE);
11b39c5158Smillert
12*3d61058aSafresh1$VERSION = '2.212';
13b39c5158Smillert
14b39c5158Smillert@ISA = qw(Exporter);
15b39c5158Smillert
16b39c5158Smillert@EXPORT= qw(
17b39c5158Smillert
18b39c5158Smillert    GZIP_ID_SIZE
19b39c5158Smillert    GZIP_ID1
20b39c5158Smillert    GZIP_ID2
21b39c5158Smillert
22b39c5158Smillert    GZIP_FLG_DEFAULT
23b39c5158Smillert    GZIP_FLG_FTEXT
24b39c5158Smillert    GZIP_FLG_FHCRC
25b39c5158Smillert    GZIP_FLG_FEXTRA
26b39c5158Smillert    GZIP_FLG_FNAME
27b39c5158Smillert    GZIP_FLG_FCOMMENT
28b39c5158Smillert    GZIP_FLG_RESERVED
29b39c5158Smillert
30b39c5158Smillert    GZIP_CM_DEFLATED
31b39c5158Smillert
32b39c5158Smillert    GZIP_MIN_HEADER_SIZE
33b39c5158Smillert    GZIP_TRAILER_SIZE
34b39c5158Smillert
35b39c5158Smillert    GZIP_MTIME_DEFAULT
36b39c5158Smillert    GZIP_XFL_DEFAULT
37b39c5158Smillert    GZIP_FEXTRA_HEADER_SIZE
38b39c5158Smillert    GZIP_FEXTRA_MAX_SIZE
39b39c5158Smillert    GZIP_FEXTRA_SUBFIELD_HEADER_SIZE
40b39c5158Smillert    GZIP_FEXTRA_SUBFIELD_ID_SIZE
41b39c5158Smillert    GZIP_FEXTRA_SUBFIELD_LEN_SIZE
42b39c5158Smillert    GZIP_FEXTRA_SUBFIELD_MAX_SIZE
43b39c5158Smillert
44b39c5158Smillert    $GZIP_FNAME_INVALID_CHAR_RE
45b39c5158Smillert    $GZIP_FCOMMENT_INVALID_CHAR_RE
46b39c5158Smillert
47b39c5158Smillert    GZIP_FHCRC_SIZE
48b39c5158Smillert
49b39c5158Smillert    GZIP_ISIZE_MAX
50b39c5158Smillert    GZIP_ISIZE_MOD_VALUE
51b39c5158Smillert
52b39c5158Smillert
53b39c5158Smillert    GZIP_NULL_BYTE
54b39c5158Smillert
55b39c5158Smillert    GZIP_OS_DEFAULT
56b39c5158Smillert
57b39c5158Smillert    %GZIP_OS_Names
58b39c5158Smillert
59b39c5158Smillert    GZIP_MINIMUM_HEADER
60b39c5158Smillert
61b39c5158Smillert    );
62b39c5158Smillert
63b39c5158Smillert# Constant names derived from RFC 1952
64b39c5158Smillert
65b39c5158Smillertuse constant GZIP_ID_SIZE                     => 2 ;
66b39c5158Smillertuse constant GZIP_ID1                         => 0x1F;
67b39c5158Smillertuse constant GZIP_ID2                         => 0x8B;
68b39c5158Smillert
69b39c5158Smillertuse constant GZIP_MIN_HEADER_SIZE             => 10 ;# minimum gzip header size
70b39c5158Smillertuse constant GZIP_TRAILER_SIZE                => 8 ;
71b39c5158Smillert
72b39c5158Smillert
73b39c5158Smillertuse constant GZIP_FLG_DEFAULT                 => 0x00 ;
74b39c5158Smillertuse constant GZIP_FLG_FTEXT                   => 0x01 ;
75b39c5158Smillertuse constant GZIP_FLG_FHCRC                   => 0x02 ; # called CONTINUATION in gzip
76b39c5158Smillertuse constant GZIP_FLG_FEXTRA                  => 0x04 ;
77b39c5158Smillertuse constant GZIP_FLG_FNAME                   => 0x08 ;
78b39c5158Smillertuse constant GZIP_FLG_FCOMMENT                => 0x10 ;
79b39c5158Smillert#use constant GZIP_FLG_ENCRYPTED              => 0x20 ; # documented in gzip sources
80b39c5158Smillertuse constant GZIP_FLG_RESERVED                => (0x20 | 0x40 | 0x80) ;
81b39c5158Smillert
82b39c5158Smillertuse constant GZIP_XFL_DEFAULT                 => 0x00 ;
83b39c5158Smillert
84b39c5158Smillertuse constant GZIP_MTIME_DEFAULT               => 0x00 ;
85b39c5158Smillert
86b39c5158Smillertuse constant GZIP_FEXTRA_HEADER_SIZE          => 2 ;
87b39c5158Smillertuse constant GZIP_FEXTRA_MAX_SIZE             => 0xFFFF ;
88b39c5158Smillertuse constant GZIP_FEXTRA_SUBFIELD_ID_SIZE     => 2 ;
89b39c5158Smillertuse constant GZIP_FEXTRA_SUBFIELD_LEN_SIZE    => 2 ;
90b39c5158Smillertuse constant GZIP_FEXTRA_SUBFIELD_HEADER_SIZE => GZIP_FEXTRA_SUBFIELD_ID_SIZE +
91b39c5158Smillert                                                 GZIP_FEXTRA_SUBFIELD_LEN_SIZE;
92b39c5158Smillertuse constant GZIP_FEXTRA_SUBFIELD_MAX_SIZE    => GZIP_FEXTRA_MAX_SIZE -
93b39c5158Smillert                                                 GZIP_FEXTRA_SUBFIELD_HEADER_SIZE ;
94b39c5158Smillert
95b39c5158Smillert
96b39c5158Smillertif (ord('A') == 193)
97b39c5158Smillert{
98b39c5158Smillert    # EBCDIC
99b39c5158Smillert    $GZIP_FNAME_INVALID_CHAR_RE = '[\x00-\x3f\xff]';
100b39c5158Smillert    $GZIP_FCOMMENT_INVALID_CHAR_RE = '[\x00-\x0a\x11-\x14\x16-\x3f\xff]';
101b39c5158Smillert
102b39c5158Smillert}
103b39c5158Smillertelse
104b39c5158Smillert{
105b39c5158Smillert    $GZIP_FNAME_INVALID_CHAR_RE       =  '[\x00-\x1F\x7F-\x9F]';
106b39c5158Smillert    $GZIP_FCOMMENT_INVALID_CHAR_RE    =  '[\x00-\x09\x11-\x1F\x7F-\x9F]';
107b39c5158Smillert}
108b39c5158Smillert
109b39c5158Smillertuse constant GZIP_FHCRC_SIZE        => 2 ; # aka CONTINUATION in gzip
110b39c5158Smillert
111b39c5158Smillertuse constant GZIP_CM_DEFLATED       => 8 ;
112b39c5158Smillert
113b39c5158Smillertuse constant GZIP_NULL_BYTE         => "\x00";
114b39c5158Smillertuse constant GZIP_ISIZE_MAX         => 0xFFFFFFFF ;
115b39c5158Smillertuse constant GZIP_ISIZE_MOD_VALUE   => GZIP_ISIZE_MAX + 1 ;
116b39c5158Smillert
117b39c5158Smillert# OS Names sourced from http://www.gzip.org/format.txt
118b39c5158Smillert
119b39c5158Smillertuse constant GZIP_OS_DEFAULT=> 0xFF ;
120b39c5158Smillert%GZIP_OS_Names = (
121b39c5158Smillert    0   => 'MS-DOS',
122b39c5158Smillert    1   => 'Amiga',
123b39c5158Smillert    2   => 'VMS',
124b39c5158Smillert    3   => 'Unix',
125b39c5158Smillert    4   => 'VM/CMS',
126b39c5158Smillert    5   => 'Atari TOS',
127b39c5158Smillert    6   => 'HPFS (OS/2, NT)',
128b39c5158Smillert    7   => 'Macintosh',
129b39c5158Smillert    8   => 'Z-System',
130b39c5158Smillert    9   => 'CP/M',
131b39c5158Smillert    10  => 'TOPS-20',
132b39c5158Smillert    11  => 'NTFS (NT)',
133b39c5158Smillert    12  => 'SMS QDOS',
134b39c5158Smillert    13  => 'Acorn RISCOS',
135b39c5158Smillert    14  => 'VFAT file system (Win95, NT)',
136b39c5158Smillert    15  => 'MVS',
137b39c5158Smillert    16  => 'BeOS',
138b39c5158Smillert    17  => 'Tandem/NSK',
139b39c5158Smillert    18  => 'THEOS',
140b39c5158Smillert    GZIP_OS_DEFAULT()   => 'Unknown',
141b39c5158Smillert    ) ;
142b39c5158Smillert
143b39c5158Smillertuse constant GZIP_MINIMUM_HEADER =>   pack("C4 V C C",
144b39c5158Smillert        GZIP_ID1, GZIP_ID2, GZIP_CM_DEFLATED, GZIP_FLG_DEFAULT,
145b39c5158Smillert        GZIP_MTIME_DEFAULT, GZIP_XFL_DEFAULT, GZIP_OS_DEFAULT) ;
146b39c5158Smillert
147b39c5158Smillert
148b39c5158Smillert1;
149