=encoding euc-jp =head1 NAME =begin original MIME::Base64 - Encoding and decoding of base64 strings =end original MIME::Base64 - base64文字列のエンコードとデコード =head1 SYNOPSIS use MIME::Base64; $encoded = encode_base64('Aladdin:open sesame'); $decoded = decode_base64($encoded); =head1 DESCRIPTION =begin original This module provides functions to encode and decode strings into the Base64 encoding specified in RFC 2045 - I. The Base64 encoding is designed to represent arbitrary sequences of octets in a form that need not be humanly readable. A 65-character subset ([A-Za-z0-9+/=]) of US-ASCII is used, enabling 6 bits to be represented per printable character. =end original このモジュールは RFC 2045 - I の中で 定義されている Base64エンコード方式への文字列のエンコードとデコードを行なう関数を 提供するモジュールです。Base64エンコード方式は人間の目に見えない、フォーム中の 任意のオクテット列を表現するのにデザインされています。65文字のUS-ASCIIのサブセット ([A-Za-z0-9+/=])が使われ、1つの表示可能な文字に6ビットが割り当てられます。 =begin original The following functions are provided: =end original 以下の関数が提供されています: =over 4 =item encode_base64($str, [$eol]) =begin original Encode data by calling the encode_base64() function. The first argument is the string to encode. The second argument is the line ending sequence to use (it is optional and defaults to C<"\n">). The returned encoded string is broken into lines of no more than 76 characters each and it will end with $eol unless it is empty. Pass an empty string as second argument if you do not want the encoded string broken into lines. =end original encode_base64() 関数を呼び出す事によってデータをエンコードします。 最初の引数はエンコードされる文字列です。2番目の引数はシーケンスを終了する時に 使われる文字です(これはオプションで、デフォルトはC<"\n">です)。 返されるエンコードされた文字列は76文字を越えないように分割され、 空文字列でなければ$eolが最後に付きます。もしエンコードされた文字列を 複数の行に分割したくない場合は、2番目の引数として空白の文字列を渡してください。 =item decode_base64($str) =begin original Decode a base64 string by calling the decode_base64() function. This function takes a single argument which is the string to decode and returns the decoded data. =end original decode_base64() 関数を呼び出す事によってデータをデコードします。 この関数はデコードする文字列である単独の引数をとり、デコードしたデータを 返します。 =begin original Any character not part of the 65-character base64 subset set is silently ignored. Characters occuring after a '=' padding character are never decoded. =end original 65文字のbase64サブセットの中にない文字は、単に無視されます。 埋め込み文字'='の後ろは決してデコードされません。 =begin original If the length of the string to decode (after ignoring non-base64 chars) is not a multiple of 4 or padding occurs too early, then a warning is generated if perl is running under C<-w>. =end original もしデコードする文字列の長さが(base64文字以外を無視した後) 4の整数倍数ではないか、埋め込み文字があまりにも早く見付かったならば、 perl が C<-w>で動作していると警告が表示されます。 =back =begin original If you prefer not to import these routines into your namespace you can call them as: =end original これらの関数をあなたの名前空間にインポートすることを好ましく 思わないのであれば、以下のように呼ぶことが出来ます: use MIME::Base64 (); $encoded = MIME::Base64::encode($decoded); $decoded = MIME::Base64::decode($encoded); =head1 DIAGNOSTICS (診断) =begin original The following warnings might be generated if perl is invoked with the C<-w> switch: =end original perlをC<-w>スイッチを付けて起動すると、以下の警告は表示されるかも しれません: =over 4 =item Premature end of base64 data =begin original The number of characters to decode is not a multiple of 4. Legal base64 data should be padded with one or two "=" characters to make its length a multiple of 4. The decoded result will anyway be as if the padding was there. =end original デコードする文字の数が4の倍数ではありません。正しいbase64データは 長さが4の整数倍になるよう、1つまたは2つの"="文字で調整すべきです。 デコードの結果は、 埋め込み文字がそこに存在するような形で 行なわれます。 =item Premature padding of base64 data =begin original The '=' padding character occurs as the first or second character in a base64 quartet. =end original 埋め込み文字'='が、base64の4文字の組での先頭または2番目として 存在します。 =back =head1 EXAMPLES =begin original If you want to encode a large file, you should encode it in chunks that are a multiple of 57 bytes. This ensures that the base64 lines line up and that you do not end up with padding in the middle. 57 bytes of data fills one complete base64 line (76 == 57*4/3): =end original もしも大きなファイルをエンコードしたいのであれば、57バイトの固まりで エンコードすべきです。これはbase64の行を確保し、中間の行が埋め込み文字で 終わらないことを確実にします。57バイトのデータは1行の完全なbase64行 (76 == 57*4/3)になります: use MIME::Base64 qw(encode_base64); open(FILE, "/var/log/wtmp") or die "$!"; while (read(FILE, $buf, 60*57)) { print encode_base64($buf); } =begin original or if you know you have enough memory =end original あるいは十分なメモリがあれば use MIME::Base64 qw(encode_base64); local($/) = undef; # slurp print encode_base64(); =begin original The same approach as a command line: =end original コマンド行からの同じアプローチは以下の通りです: perl -MMIME::Base64 -0777 -ne 'print encode_base64($_)' and Joerg Reichelt and code posted to comp.lang.perl <3pd2lp$6gf@wsinti07.win.tue.nl> by Hans Mulder =end original Martijn Koster と Joerg Reichelt によって書かれたLWP::Base64、 そしてHans Mulder により comp.lang.perl <3pd2lp$6gf@wsinti07.win.tue.nl>にポストされたコードを 少しだけベースにしています。 =begin original The XS implementation use code from metamail. Copyright 1991 Bell Communications Research, Inc. (Bellcore) =end original XSの実装はmetamailのコードを使っています。 Copyright 1991 Bell Communications Research, Inc. (Bellcore) =head1 翻訳者 川合孝典 (GCD00051@nifty.ne.jp)