MIME-Base64-3.08 >
2.12
との差分
MIME::Base64 2.12 と 3.08 の差分
1 | 1 | |
2 | 2 | =encoding euc-jp |
3 | 3 | |
4 | 4 | =head1 NAME |
5 | 5 | |
6 | 6 | =begin original |
7 | 7 | |
8 | 8 | MIME::Base64 - Encoding and decoding of base64 strings |
9 | 9 | |
10 | 10 | =end original |
11 | 11 | |
12 | 12 | MIME::Base64 - base64文字列のエンコードとデコード |
13 | 13 | |
14 | 14 | =head1 SYNOPSIS |
15 | 15 | |
16 | 16 | use MIME::Base64; |
17 | 17 | |
18 | 18 | $encoded = encode_base64('Aladdin:open sesame'); |
19 | 19 | $decoded = decode_base64($encoded); |
20 | 20 | |
21 | 21 | =head1 DESCRIPTION |
22 | 22 | |
23 | 23 | =begin original |
24 | 24 | |
25 | This module provides functions to encode and decode strings into the | |
25 | This module provides functions to encode and decode strings into and from the | |
26 | ||
26 | base64 encoding specified in RFC 2045 - I<MIME (Multipurpose Internet | |
27 | Mail Extensions)>. The | |
27 | Mail Extensions)>. The base64 encoding is designed to represent | |
28 | 28 | arbitrary sequences of octets in a form that need not be humanly |
29 | 29 | readable. A 65-character subset ([A-Za-z0-9+/=]) of US-ASCII is used, |
30 | 30 | enabling 6 bits to be represented per printable character. |
31 | 31 | |
32 | 32 | =end original |
33 | 33 | |
34 | このモジュールは | |
34 | このモジュールは、RFC 2045 - | |
35 | 定義されている | |
35 | I<MIME (Multipurpose Internet Mail Extensions)> で定義されている | |
36 | ||
36 | base64 エンコーディングと文字列の間のエンコードとデコードを | |
37 | ||
37 | 行なう関数を提供するモジュールです。 | |
38 | ||
38 | base64 エンコーディングは、任意のオクテット列を、 | |
39 | 人間可読である必要のない形式で表現するために設計されています。 | |
40 | 65 文字の US-ASCII の部分集合 ([A-Za-z0-9+/=]) が使われ、一つの表示可能文字に | |
41 | 6 ビットが割り当てられます。 | |
39 | 42 | |
40 | 43 | =begin original |
41 | 44 | |
42 | 45 | The following functions are provided: |
43 | 46 | |
44 | 47 | =end original |
45 | 48 | |
46 | ||
49 | 次の関数が提供されています: | |
47 | 50 | |
48 | 51 | =over 4 |
49 | 52 | |
50 | =item encode_base64($str | |
53 | =item encode_base64($str) | |
51 | 54 | |
55 | =item encode_base64($str, $eol); | |
56 | ||
52 | 57 | =begin original |
53 | 58 | |
54 | 59 | Encode data by calling the encode_base64() function. The first |
55 | argument is the string to encode. The second argument is the | |
60 | argument is the string to encode. The second argument is the | |
56 | ending sequence to use | |
61 | line-ending sequence to use. It is optional and defaults to "\n". The | |
57 | 62 | returned encoded string is broken into lines of no more than 76 |
58 | 63 | characters each and it will end with $eol unless it is empty. Pass an |
59 | 64 | empty string as second argument if you do not want the encoded string |
60 | broken into lines. | |
65 | to be broken into lines. | |
61 | 66 | |
62 | 67 | =end original |
63 | 68 | |
64 | 69 | encode_base64() 関数を呼び出す事によってデータをエンコードします。 |
65 | 最初の引数はエンコードされる文字列です。 | |
70 | 最初の引数はエンコードされる文字列です。 | |
66 | 使われる文字です | |
71 | 2 番目の引数はシーケンスを終了する時に使われる文字です。 | |
67 | ||
72 | これはオプションで、デフォルトは "\n" です。 | |
68 | ||
73 | 返されるエンコードされた文字列は 76 文字を越えないように分割され、 | |
69 | ||
74 | 空文字列でなければ $eol が最後に付きます。 | |
75 | エンコードされた文字列を複数の行に分割したくない場合は、2 番目の引数として | |
76 | 空文字列を渡してください。 | |
70 | 77 | |
71 | 78 | =item decode_base64($str) |
72 | 79 | |
73 | 80 | =begin original |
74 | 81 | |
75 | 82 | Decode a base64 string by calling the decode_base64() function. This |
76 | 83 | function takes a single argument which is the string to decode and |
77 | 84 | returns the decoded data. |
78 | 85 | |
79 | 86 | =end original |
80 | 87 | |
81 | 88 | decode_base64() 関数を呼び出す事によってデータをデコードします。 |
82 | 89 | この関数はデコードする文字列である単独の引数をとり、デコードしたデータを |
83 | 90 | 返します。 |
84 | 91 | |
85 | 92 | =begin original |
86 | 93 | |
87 | Any character not part of the 65-character base64 subset | |
94 | Any character not part of the 65-character base64 subset is | |
88 | silently ignored. Characters occuring after a '=' padding character | |
95 | silently ignored. Characters occurring after a '=' padding character | |
89 | 96 | are never decoded. |
90 | 97 | |
91 | 98 | =end original |
92 | 99 | |
93 | 65文字のbase64 | |
100 | 65 文字の base64 部分集合の中にない文字は、単に無視されます。 | |
94 | ||
101 | 詰め物文字 '=' の後ろの文字は決してデコードされません。 | |
95 | 102 | |
96 | 103 | =begin original |
97 | 104 | |
98 | If the length of the string to decode | |
105 | If the length of the string to decode, after ignoring | |
99 | non-base64 chars | |
106 | non-base64 chars, is not a multiple of 4 or if padding occurs too early, | |
100 | 107 | then a warning is generated if perl is running under C<-w>. |
101 | 108 | |
102 | 109 | =end original |
103 | 110 | |
104 | ||
111 | base64 文字以外を無視した後、デコードする文字列の長さが | |
105 | 4の整数倍 | |
112 | 4 の整数倍ではないか、詰め物文字があまりにも早く見付かった場合、 | |
106 | perl が C<-w>で動作していると警告が表示されます。 | |
113 | perl が C<-w> で動作していると警告が表示されます。 | |
107 | 114 | |
108 | 115 | =back |
109 | 116 | |
110 | 117 | =begin original |
111 | 118 | |
112 | If you prefer not to import these routines into your namespace you can | |
119 | If you prefer not to import these routines into your namespace, you can | |
113 | 120 | call them as: |
114 | 121 | |
115 | 122 | =end original |
116 | 123 | |
117 | 124 | これらの関数をあなたの名前空間にインポートすることを好ましく |
118 | 125 | 思わないのであれば、以下のように呼ぶことが出来ます: |
119 | 126 | |
120 | 127 | use MIME::Base64 (); |
121 | 128 | $encoded = MIME::Base64::encode($decoded); |
122 | 129 | $decoded = MIME::Base64::decode($encoded); |
123 | 130 | |
124 | 131 | =head1 DIAGNOSTICS |
125 | 132 | |
126 | 133 | (診断) |
127 | 134 | |
128 | 135 | =begin original |
129 | 136 | |
130 | The following warnings | |
137 | The following warnings can be generated if perl is invoked with the | |
131 | 138 | C<-w> switch: |
132 | 139 | |
133 | 140 | =end original |
134 | 141 | |
135 | perlをC<-w>スイッチを付けて起動すると、以下の警告 | |
142 | perl を C<-w> スイッチを付けて起動すると、以下の警告が | |
136 | ||
143 | 表示されることがあります: | |
137 | 144 | |
138 | 145 | =over 4 |
139 | 146 | |
140 | 147 | =item Premature end of base64 data |
141 | 148 | |
142 | 149 | =begin original |
143 | 150 | |
144 | 151 | The number of characters to decode is not a multiple of 4. Legal |
145 | 152 | base64 data should be padded with one or two "=" characters to make |
146 | its length a multiple of 4. The decoded result will | |
153 | its length a multiple of 4. The decoded result will be the same | |
147 | the padding | |
154 | whether the padding is present or not. | |
148 | 155 | |
149 | 156 | =end original |
150 | 157 | |
151 | デコードする文字の数が4の倍数ではありません。 | |
158 | デコードする文字の数が 4 の倍数ではありません。 | |
152 | ||
159 | 正当な base64 データは | |
153 | ||
160 | 長さが 4 の整数倍になるよう、一つまたは二つの "=" 文字で調整されている | |
154 | ||
161 | 必要があります。 | |
162 | デコードの結果は、詰め物文字があるかどうかに関わらず同じです。 | |
155 | 163 | |
156 | 164 | =item Premature padding of base64 data |
157 | 165 | |
158 | 166 | =begin original |
159 | 167 | |
160 | 168 | The '=' padding character occurs as the first or second character |
161 | 169 | in a base64 quartet. |
162 | 170 | |
163 | 171 | =end original |
164 | 172 | |
165 | ||
173 | 詰め物文字 '=' が、base64 の 4 文字の組での先頭または 2 番目として | |
166 | ||
174 | 現れています。 | |
167 | 175 | |
168 | 176 | =back |
169 | 177 | |
178 | =begin original | |
179 | ||
180 | The following exception can be raised: | |
181 | ||
182 | =end original | |
183 | ||
184 | 次の例外が発生することがあります: | |
185 | ||
186 | =over 4 | |
187 | ||
188 | =item Wide character in subroutine entry | |
189 | ||
190 | =begin original | |
191 | ||
192 | The string passed to encode_base64() contains characters with code | |
193 | above 255. The base64 encoding is only defined for single-byte | |
194 | characters. Use the Encode module to select the byte encoding you | |
195 | want. | |
196 | ||
197 | =end original | |
198 | ||
199 | encode_base64() に渡された文字列に、255 を超える符号位置を持つ文字が | |
200 | 含まれています。 | |
201 | base64 エンコーディングは単一バイト文字に対してのみ定義されています。 | |
202 | 求めているバイトエンコーディングを選ぶために Encode モジュールを | |
203 | 使ってください。 | |
204 | ||
205 | =back | |
206 | ||
170 | 207 | =head1 EXAMPLES |
171 | 208 | |
209 | (例) | |
210 | ||
172 | 211 | =begin original |
173 | 212 | |
174 | 213 | If you want to encode a large file, you should encode it in chunks |
175 | 214 | that are a multiple of 57 bytes. This ensures that the base64 lines |
176 | 215 | line up and that you do not end up with padding in the middle. 57 |
177 | 216 | bytes of data fills one complete base64 line (76 == 57*4/3): |
178 | 217 | |
179 | 218 | =end original |
180 | 219 | |
181 | ||
220 | 大きなファイルをエンコードしたい場合、、57 バイトの倍数の固まりで | |
182 | エンコードすべきです。 | |
221 | エンコードすべきです。 | |
183 | ||
222 | これは base64 の行を確保し、中間の行が詰め物文字で | |
184 | ||
223 | 終わらないことを保証にします。 | |
224 | 57 バイトのデータは 1 行の完全な base64 行 | |
225 | (76 == 57*4/3) になります: | |
185 | 226 | |
186 | 227 | use MIME::Base64 qw(encode_base64); |
187 | 228 | |
188 | 229 | open(FILE, "/var/log/wtmp") or die "$!"; |
189 | 230 | while (read(FILE, $buf, 60*57)) { |
190 | 231 | print encode_base64($buf); |
191 | 232 | } |
192 | 233 | |
193 | 234 | =begin original |
194 | 235 | |
195 | 236 | or if you know you have enough memory |
196 | 237 | |
197 | 238 | =end original |
198 | 239 | |
199 | あるいは十分なメモリがあれば | |
240 | あるいは十分なメモリがあれば: | |
200 | 241 | |
201 | 242 | use MIME::Base64 qw(encode_base64); |
202 | 243 | local($/) = undef; # slurp |
203 | 244 | print encode_base64(<STDIN>); |
204 | 245 | |
205 | 246 | =begin original |
206 | 247 | |
207 | 248 | The same approach as a command line: |
208 | 249 | |
209 | 250 | =end original |
210 | 251 | |
211 | 252 | コマンド行からの同じアプローチは以下の通りです: |
212 | 253 | |
213 | 254 | perl -MMIME::Base64 -0777 -ne 'print encode_base64($_)' <file |
214 | 255 | |
215 | 256 | =begin original |
216 | 257 | |
217 | Decoding does not need slurp mode if | |
258 | Decoding does not need slurp mode if every line contains a multiple | |
218 | of | |
259 | of four base64 chars: | |
219 | 260 | |
220 | 261 | =end original |
221 | 262 | |
222 | すべての行にbase64文字が4の倍数入っていれば、デコードは | |
263 | すべての行に base64 文字が 4 の倍数個入っていれば、デコードは | |
223 | 必要としません: | |
264 | 吸い込みモードを必要としません: | |
224 | 265 | |
225 | 266 | perl -MMIME::Base64 -ne 'print decode_base64($_)' <file |
226 | 267 | |
268 | =begin original | |
269 | ||
270 | Perl v5.8 and better allow extended Unicode characters in strings. | |
271 | Such strings cannot be encoded directly, as the base64 | |
272 | encoding is only defined for single-byte characters. The solution is | |
273 | to use the Encode module to select the byte encoding you want. For | |
274 | example: | |
275 | ||
276 | =end original | |
277 | ||
278 | Perl v5.8 以降では文字列に拡張 Unicode 文字を使えます。 | |
279 | そのような文字列は直接エンコードできません; | |
280 | base64 エンコーディングは単一バイト文字に対してのみ定義されているからです。 | |
281 | 解決法は、求めているバイトエンコーディングを選ぶために Encode モジュールを | |
282 | 使うことです。 | |
283 | 例えば: | |
284 | ||
285 | use MIME::Base64 qw(encode_base64); | |
286 | use Encode qw(encode); | |
287 | ||
288 | $encoded = encode_base64(encode("UTF-8", "\x{FFFF}\n")); | |
289 | print $encoded; | |
290 | ||
227 | 291 | =head1 COPYRIGHT |
228 | 292 | |
229 | Copyright 1995-1999, 2001 Gisle Aas. | |
293 | Copyright 1995-1999, 2001-2004 Gisle Aas. | |
230 | 294 | |
231 | 295 | This library is free software; you can redistribute it and/or |
232 | 296 | modify it under the same terms as Perl itself. |
233 | 297 | |
234 | 298 | =begin original |
235 | 299 | |
236 | 300 | Distantly based on LWP::Base64 written by Martijn Koster |
237 | 301 | <m.koster@nexor.co.uk> and Joerg Reichelt <j.reichelt@nexor.co.uk> and |
238 | 302 | code posted to comp.lang.perl <3pd2lp$6gf@wsinti07.win.tue.nl> by Hans |
239 | 303 | Mulder <hansm@wsinti07.win.tue.nl> |
240 | 304 | |
241 | 305 | =end original |
242 | 306 | |
243 | Martijn Koster<m.koster@nexor.co.uk> と | |
307 | Martijn Koster<m.koster@nexor.co.uk> と | |
244 | Joerg Reichelt <j.reichelt@nexor.co.uk>によって書かれたLWP::Base64、 | |
308 | Joerg Reichelt <j.reichelt@nexor.co.uk>によって書かれた LWP::Base64、 | |
245 | そしてHans Mulder <hansm@wsinti07.win.tue.nl>により | |
309 | そして Hans Mulder <hansm@wsinti07.win.tue.nl> により | |
246 | comp.lang.perl <3pd2lp$6gf@wsinti07.win.tue.nl>に | |
310 | comp.lang.perl <3pd2lp$6gf@wsinti07.win.tue.nl>に投稿されたコードを | |
247 | 311 | 少しだけベースにしています。 |
248 | 312 | |
249 | 313 | =begin original |
250 | 314 | |
251 | The XS implementation use code from metamail. Copyright 1991 Bell | |
315 | The XS implementation uses code from metamail. Copyright 1991 Bell | |
252 | 316 | Communications Research, Inc. (Bellcore) |
253 | 317 | |
254 | 318 | =end original |
255 | 319 | |
256 | XSの実装はmetamailのコードを使っています。 | |
320 | XS の実装は metamail のコードを使っています。 | |
257 | 321 | Copyright 1991 Bell Communications Research, Inc. (Bellcore) |
258 | 322 | |
259 | =head1 | |
323 | =head1 SEE ALSO | |
260 | 324 | |
261 | ||
325 | L<MIME::QuotedPrint> | |
326 | ||
327 | =begin meta | |
328 | ||
329 | Translate: 川合孝典 <GCD00051@nifty.ne.jp> | |
330 | Update: Kentaro Shirakata <argrath@ub32.org> (3.08) | |
331 | Status: completed | |
332 | ||
333 | =end meta | |
334 | ||
335 | =cut |