1Mojo::ByteStream(3)   User Contributed Perl Documentation  Mojo::ByteStream(3)
2
3
4

NAME

6       Mojo::ByteStream - ByteStream
7

SYNOPSIS

9           use Mojo::ByteStream;
10
11           my $stream = Mojo::ByteStream->new('foobarbaz');
12
13           $stream->camelize;
14           $stream->decamelize;
15           $stream->b64_encode;
16           $stream->b64_decode;
17           $stream->encode('UTF-8');
18           $stream->decode('UTF-8');
19           $stream->hmac_md5_sum('secret');
20           $stream->hmac_sha1_sum('secret');
21           $stream->html_escape;
22           $stream->html_unescape;
23           $stream->md5_bytes;
24           $stream->md5_sum;
25           $stream->qp_encode;
26           $stream->qp_decode;
27           $stream->quote;
28           $stream->sha1_bytes;
29           $stream->sha1_sum;
30           $stream->trim;
31           $stream->unquote;
32           $stream->url_escape;
33           $stream->url_sanitize;
34           $stream->url_unescape;
35           $stream->xml_escape;
36           $stream->punycode_encode;
37           $stream->punycode_decode;
38
39           my $size = $stream->size;
40
41           my $stream2 = $stream->clone;
42           print $stream2->to_string;
43           $stream2->say;
44
45           # Chained
46           my $stream = Mojo::ByteStream->new('foo bar baz')->quote;
47           $stream = $stream->unquote->encode('UTF-8)->b64_encode;
48           print "$stream";
49
50           # Alternative constructor
51           use Mojo::ByteStream 'b';
52           my $stream = b('foobarbaz')->html_escape;
53
54           # Buffering
55           my $stream = Mojo::ByteStream->new;
56           $stream->add_chunk('bar');
57           my $foo = $stream->remove(3);
58           my $bar = $stream->empty;
59

DESCRIPTION

61       Mojo::ByteStream provides portable text and bytestream manipulation
62       functions.
63

ATTRIBUTES

65       Mojo::ByteStream implements the following attributes.
66
67   "raw_size"
68           my $size = $stream->raw_size;
69           $stream  = $stream->raw_size(23);
70
71       Raw bytestream size in bytes.
72

METHODS

74       Mojo::ByteStream inherits all methods from Mojo::Base and implements
75       the following new ones.
76
77   "new"
78           my $stream = Mojo::ByteStream->new($string);
79
80       Construct a new Mojo::ByteStream object.
81
82   "add_chunk"
83           $stream = $stream->add_chunk('foo');
84
85       Add chunk of data to bytestream.
86
87   "b64_decode"
88           $stream = $stream->b64_decode;
89
90       Base 64 decode bytestream.
91
92   "b64_encode"
93           $stream = $stream->b64_encode;
94           $stream = $stream->b64_encode('');
95
96       Base 64 encode bytestream.
97
98   "camelize"
99           $stream = $stream->camelize;
100
101       Camelize bytestream.
102
103           foo_bar -> FooBar
104
105   "clone"
106           my $stream2 = $stream->clone;
107
108       Clone bytestream.
109
110   "contains"
111           my $position = $stream->contains('something');
112
113       Check if bytestream contains a specific string.
114
115   "decamelize"
116           $stream = $stream->decamelize;
117
118       Decamelize bytestream.
119
120           FooBar -> foo_bar
121
122   "decode"
123           $stream = $stream->decode($encoding);
124
125       Decode bytestream.
126
127           $stream->decode('UTF-8')->to_string;
128
129   "empty"
130           my $chunk = $stream->empty;
131
132       Empty bytestream.
133
134   "encode"
135           $stream = $stream->encode($encoding);
136
137       Encode bytestream.
138
139           $stream->encode('UTF-8')->to_string;
140
141   "get_line"
142           my $line = $stream->get_line;
143
144       Extract a whole line from start of bytestream.  Lines are expected to
145       end with "0x0d 0x0a" or 0x0a.
146
147   "hmac_md5_sum"
148           $stream = $stream->hmac_md5_sum($secret);
149
150       Turn bytestream into HMAC-MD5 checksum of old content.
151
152   "hmac_sha1_sum"
153           $stream = $stream->hmac_sha1_sum($secret);
154
155       Turn bytestream into HMAC-SHA1 checksum of old content.  Note that Perl
156       5.10 or Digest::SHA are required for "SHA1" support.
157
158   "html_escape"
159           $stream = $stream->html_escape;
160
161       HTML escape bytestream.
162
163   "html_unescape"
164           $stream = $stream->html_unescape;
165
166       HTML unescape bytestream.
167
168   "md5_bytes"
169           $stream = $stream->md5_bytes;
170
171       Turn bytestream into binary MD5 checksum of old content.
172
173   "md5_sum"
174           $stream = $stream->md5_sum;
175
176       Turn bytestream into MD5 checksum of old content.
177
178   "punycode_decode"
179           $stream = $stream->punycode_decode;
180
181       Punycode decode bytestream, as described in RFC 3492.
182
183   "punycode_encode"
184           $stream = $stream->punycode_encode;
185
186       Punycode encode bytestream, as described in RFC 3492.
187
188   "qp_decode"
189           $stream = $stream->qp_decode;
190
191       Quoted Printable decode bytestream.
192
193   "qp_encode"
194           $stream = $stream->qp_encode;
195
196       Quoted Printable encode bytestream.
197
198   "quote"
199           $stream = $stream->quote;
200
201       Quote bytestream.
202
203   "remove"
204           my $chunk = $stream->remove(4);
205           my $chunk = $stream->remove(4, 'abcd');
206
207       Remove a specific number of bytes from bytestream.
208
209   "say"
210           $stream->say;
211           $stream->say(*STDERR);
212
213       Print bytestream to handle or STDOUT and append a newline.
214
215   "sha1_bytes"
216           $stream = $stream->sha1_bytes;
217
218       Turn bytestream into binary SHA1 checksum of old content.  Note that
219       Perl 5.10 or Digest::SHA are required for "SHA1" support.
220
221   "sha1_sum"
222           $stream = $stream->sha1_sum;
223
224       Turn bytestream into SHA1 checksum of old content.  Note that Perl 5.10
225       or Digest::SHA are required for "SHA1" support.
226
227   "size"
228           my $size = $stream->size;
229
230       Size of bytestream.
231
232   "to_string"
233           my $string = $stream->to_string;
234
235       Stringify bytestream.
236
237   "trim"
238           $stream = $stream->trim;
239
240       Trim whitespace characters from both ends of bytestream.
241
242   "unquote"
243           $stream = $stream->unquote;
244
245       Unquote bytestream.
246
247   "url_escape"
248           $stream = $stream->url_escape;
249           $stream = $stream->url_escape('A-Za-z0-9\-\.\_\~');
250
251       URL escape bytestream.
252
253   "url_sanitize"
254           $stream = $stream->url_sanitize;
255
256       URL sanitize bytestream.
257
258   "url_unescape"
259           $stream = $stream->url_unescape;
260
261       URL unescape bytestream.
262
263   "xml_escape"
264           $stream = $stream->xml_escape;
265
266       XML escape bytestream, this is a much faster version of "html_escape"
267       escaping only the characters "&", "<", ">", """ and "'".
268

SEE ALSO

270       Mojolicious, Mojolicious::Guides, <http://mojolicious.org>.
271
272
273
274perl v5.12.3                      2010-08-12               Mojo::ByteStream(3)
Impressum