RZ

01: # RZStructure.pl # the actual synthesize algorithm
02:
03: use strict;
04:
05: package RZStructure;
06:
07: # RZA - header and stream structure
08: # RZB - signature table
09: # RZC - compressed data stream
10:
11: ######## ######## ######## ######## ######## ######## ######## ######## ########
12:
13: {
14:     my $magic =
15:       pack( "C", 159 )."rgz".13.10.26.10."zlib".0.0.4.0.
16:       pack( "N4",
17:           555777555, # checksum bits  0-31
18:           777222777, # checksum bits 32-63
19:           999555999, # checksum bits 64-95
20:           1<<16,    # blocksize 8192 bytes
21:       );
22:     
23:     sub checkmagic {
24:         # check the header --- the magic and version number
25:         return substr( $_[0], 0 ,32 ) eq $magic or die
26:           "The remote file is not an rz file\n";
27:     }
28:
29:     sub printmagic {
30:         return unless $_[0];
31:         print STDERR "  Version rgz: ";
32:         {
33:             local( $, ) = ".";
34:             print STDERR unpack( "U16", $magic );
35:         }
36:         print STDERR "\n";
37:     }
38: }
39:
40: ######## ######## ######## ######## ######## ######## ######## ######## ########
41:
42: sub processheader {
43:     our (
44:         $nblks, # number of complete 8192K source blocks
45:         $rzcrc, # crc of the compressed stream
46:         $scend, # end (size) of the source stream
47:         $rzend, # end (size) of the compressed stream
48:
49:         $ncont, # number of blocks before compression reinitializes
50:         $rzczr, # initial (zero) crc value
51:         $scoff, # initial offset into source stream before block 0
52:         $rzoff, # initial offset into compressed stream before block 0
53:     ) = unpack( "x32N8", $_[0] );
54:
55:     $ncont == 0 and $rzczr == 0 or die;
56:     $scoff == 0 and $rzoff == 0 or die;
57:
58:     our $filesize = ( our $wrappersize = 64 + 16 * $nblks ) + $rzend;
59: }
60:
61: ######## ######## ######## ######## ######## ######## ######## ######## ########
62:
63: {
64:     my @rztab;
65:
66:     sub processtable {
67:         @rztab = (
68:             0,
69:             unpack( "x64(x12N)*", $_[0] ),
70:             our $rzend,
71:         );
72:     }
73:
74:     sub rzat { $rztab[ $_[0]+0 ] }
75:     sub rzto { $rztab[ $_[0]+1 ] }
76:     sub rzsize { $rztab[ $_[0]+1 ] - $rztab[ $_[0]+0 ] }
77:     sub rzatbegin { -0 }
78:     sub rztobegin { -1 }
79:     sub rzatend { $#rztab-0 }
80:     sub rztoend { $#rztab-1 }
81: }
82:
83: ######## ######## ######## ######## ######## ######## ######## ######## ########
84:
85: sub processwrapper {
86:     &checkmagic;
87:     &processheader;
88:     &processtable;
89:
90:     our $rzwrapper = $_[0];
91: }
92:
93: ######## ######## ######## ######## ######## ######## ######## ######## ########
94:
95: # RZStructure.pl # the actual synthesize algorithm
96:
97: 1;