=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 and from 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+/=]) が使われ、一つの表示可能文字に 6 ビットが割り当てられます。 =begin original The following functions are provided: =end original 次の関数が提供されています: =over 4 =item encode_base64($str) =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 "\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 to be broken into lines. =end original encode_base64() 関数を呼び出す事によってデータをエンコードします。 最初の引数はエンコードされる文字列です。 2 番目の引数はシーケンスを終了する時に使われる文字です。 これはオプションで、デフォルトは "\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 is silently ignored. Characters occurring 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 if 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 can 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 be the same whether the padding is present or not. =end original デコードする文字の数が 4 の倍数ではありません。 正当な base64 データは 長さが 4 の整数倍になるよう、一つまたは二つの "=" 文字で調整されている 必要があります。 デコードの結果は、詰め物文字があるかどうかに関わらず同じです。 =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 =begin original The following exception can be raised: =end original 次の例外が発生することがあります: =over 4 =item Wide character in subroutine entry =begin original The string passed to encode_base64() contains characters with code above 255. The base64 encoding is only defined for single-byte characters. Use the Encode module to select the byte encoding you want. =end original encode_base64() に渡された文字列に、255 を超える符号位置を持つ文字が 含まれています。 base64 エンコーディングは単一バイト文字に対してのみ定義されています。 求めているバイトエンコーディングを選ぶために Encode モジュールを 使ってください。 =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 uses code from metamail. Copyright 1991 Bell Communications Research, Inc. (Bellcore) =end original XS の実装は metamail のコードを使っています。 Copyright 1991 Bell Communications Research, Inc. (Bellcore) =head1 SEE ALSO L =begin meta Translate: 川合孝典 Update: Kentaro Shirakata (3.08) Status: completed =end meta =cut