|
|
@ -21,7 +21,7 @@ sub new { |
|
|
|
|
|
|
|
|
|
|
|
sub size { |
|
|
|
sub size { |
|
|
|
my ($self) = @_; |
|
|
|
my ($self) = @_; |
|
|
|
return length $self->{data}; |
|
|
|
return _length_bytes($self->{data}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
## accessors / setters |
|
|
|
## accessors / setters |
|
|
@ -67,51 +67,51 @@ sub name { |
|
|
|
|
|
|
|
|
|
|
|
## import functions |
|
|
|
## import functions |
|
|
|
|
|
|
|
|
|
|
|
sub load { |
|
|
|
sub from_binary { |
|
|
|
my ($self, $path) = @_; |
|
|
|
my ($self, $bin) = @_; |
|
|
|
|
|
|
|
|
|
|
|
open my $FH, '<', $path or |
|
|
|
return unless defined $bin and length($bin) > 0; |
|
|
|
return $self->error("can't open file: $path -- $!"); |
|
|
|
$self->{data} = _encode_uue($bin); |
|
|
|
local $/ = undef; |
|
|
|
|
|
|
|
$self->{data} = <$FH>; |
|
|
|
|
|
|
|
close $FH; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sub parse_uue_line { |
|
|
|
sub add_uue_line { |
|
|
|
my ($self, $line) = @_; |
|
|
|
my ($self, $line) = @_; |
|
|
|
|
|
|
|
my $len = length($line); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($len == 80) { |
|
|
|
|
|
|
|
# optimization |
|
|
|
|
|
|
|
$self->{data} .= $line; |
|
|
|
|
|
|
|
return 60; |
|
|
|
|
|
|
|
} elsif ($len % 4 == 1) { |
|
|
|
# 1-char uue chunk with 6 significant bits can't hold 1 byte with 8 bits |
|
|
|
# 1-char uue chunk with 6 significant bits can't hold 1 byte with 8 bits |
|
|
|
return $self->error("bad uuencoded data (odd length)\n") |
|
|
|
return $self->error("bad uuencoded data (odd length)\n"); |
|
|
|
if length($line) % 4 == 1; |
|
|
|
} elsif ($len == 0) { |
|
|
|
|
|
|
|
return 0; |
|
|
|
# decode uue to binary form |
|
|
|
} # else... |
|
|
|
my $bytes = _decode_uue($line); |
|
|
|
|
|
|
|
$self->{data} .= $bytes; |
|
|
|
chomp $line; |
|
|
|
|
|
|
|
$self->{data} .= $line; |
|
|
|
return length $bytes; |
|
|
|
return _length_bytes($line); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
## export functions |
|
|
|
## export functions |
|
|
|
|
|
|
|
|
|
|
|
sub binary { |
|
|
|
sub to_binary { |
|
|
|
my ($self, $bin) = @_; |
|
|
|
my ($self) = @_; |
|
|
|
if (defined $bin) { |
|
|
|
return _decode_uue($self->{data}); |
|
|
|
$self->{data} = $bin; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return $self->{data}; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sub uue_line { |
|
|
|
sub uue_string { |
|
|
|
my ($self) = @_; |
|
|
|
my ($self) = @_; |
|
|
|
return _encode_uue($self->{data}); |
|
|
|
return $self->{data}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sub uue_block { |
|
|
|
sub uue_block { |
|
|
|
my ($self) = @_; |
|
|
|
my ($self) = @_; |
|
|
|
|
|
|
|
|
|
|
|
my $uue = $self->uue_line; |
|
|
|
my $uue = $self->uue_string; |
|
|
|
my $cap = ($self->{type} eq 'font') ? 'fontname' : 'filename'; |
|
|
|
my $cap = ($self->{type} eq 'font') ? 'fontname' : 'filename'; |
|
|
|
my $out = sprintf '%s: %s%s', $cap, $self->{name}, $self->{eol}; |
|
|
|
my $out = sprintf '%s: %s%s', $cap, $self->{name}, $self->{eol}; |
|
|
|
while (my $line = substr($uue, 0, 80, '')) { |
|
|
|
while (my $line = substr($uue, 0, 80, '')) { |
|
|
@ -124,6 +124,14 @@ sub uue_block { |
|
|
|
|
|
|
|
|
|
|
|
## private UUE functions |
|
|
|
## private UUE functions |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub _length_bytes { |
|
|
|
|
|
|
|
my ($uue) = @_; |
|
|
|
|
|
|
|
my $len = length $uue; |
|
|
|
|
|
|
|
my $tail = $len % 4; |
|
|
|
|
|
|
|
my $size = int($len / 4) * 3; |
|
|
|
|
|
|
|
return $size + int(($tail * 6) / 8); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sub _decode_uue { |
|
|
|
sub _decode_uue { |
|
|
|
my ($uue) = @_; |
|
|
|
my ($uue) = @_; |
|
|
|
my $bytes = ''; |
|
|
|
my $bytes = ''; |
|
|
|