Perlスクリプトにバイナリファイル埋め込む方法
読了まで:約1分
- [[Perl]] の
[[スクリプト]] の [[バイナリファイル]] を [[テキスト]] で 埋め込む
しばらく
まず、uuencode
と
で、uuencode
#!perl
use strict;
use warings;
my $file = shift @ARGV;
open( my $fh, '<', $file ) or die "Cannot open file: ${file}: ${!}";
binmode $fh;
my $data = do { local $/; <$fh> };
close $fh;
my $text = pack('u*', $data);
print $text;
とbin2text.pl
と
$ ./bin2text.pl {binaryfile}
とuuencode
の
んで、
#!perl
use strict;
use warnings;
my $source = q{uuencode形式のデータ};
my $binary = unpack('u*', $source);
と
んで、
#!perl
use strict;
use warnings;
# 1 x 1の透明なgifファイル
my $image = unpack('u*', q{K1TE&.#EA`0`!`(```/_______R'Y!`$*``$`+``````!``$```("3`$`.P``});
my $length = legnth($image);
return sub {
return [
200,
[
'Content-Type' => 'image/gif',
'Content-Length' => $length,
],
[[ $image ]]
]
};
と
で、
まあuuencode
ってBase64
MIME::Base64
uuencode
を
ま