HTTP::Promise::Stream::Base64 - Stream Encoder for Base64 Encoding
use HTTP::Promise::Stream::Base64; my $s = HTTP::Promise::Stream::Base64->new || die( HTTP::Promise::Stream::Base64->error, "\n" ); $s->encode( $input => $output, eol => "\n" ) || die( $s->error ); $s->decode( $input => $output ) || die( $s->error ); HTTP::Promise::Stream::Base64::encode_b64( $input => $output, eol => "\n" ) || die( $HTTP::Promise::Stream::Base64::Base64Error ); HTTP::Promise::Stream::Base64::decode_b64( $input => $output, eol => "\n" ) || die( $HTTP::Promise::Stream::Base64::Base64Error );
v0.1.0
This implements an encoding and decoding mechanism for base64 encoding using either of the following on input and output:
filepath
If the parameter is neither a scalar reference nor a file handle, it will be assumed to be a file path.
file handle
This can be a native file handle, or an object oriented one as long as it implements the print or write, and read methods. The read method is expected to return the number of bytes read or undef upon error. The print and write methods are expected to simply return true upon success and undef upon error.
print
write
read
undef
Alternatively, those methods can die and those exceptions wil be caught.
scalar reference
This can be a simple scalar reference, or an object scalar reference.
Creates a new HTTP::Promise::Stream::Base64 object and returns it.
This takes 2 arguments: an input and an output. Each one can be either a file path, a file handle, or a scalar reference.
It will decode the base64 encoded data and write the result into the output.
It returns true upon success and sets an error and return undef upon error.
It will encode the data into base64 encoded data and write the result into the output.
If the option eol (standing for "End of line") is provided, it will be used to break down the base64 encoded into lines of 76 characters ending with the eol. If eol is not provided, it will default to $/, which usually is \n. If you want base64 data that are not borken down into 76 characters line, then pass an empty eol parameter, such as:
$/
\n
my $s = HTTP::Promise::Stream::Base64->new; $s->encode( $from => $to, eol => undef ); # or eol => ''
The following class functions are available and can also be exported, such as:
use HTTP::Promise::Stream::Base64 qw( decode_b64 encode_b64 );
This takes the same 2 arguments used in "decode": an input and an output. Each one can be either a file path, a file handle, or a scalar reference.
It returns true upon success, and upon error, it will set the error in the global variable $Base64Error and return undef
$Base64Error
my $decoded = HTTP::Promise::Stream::Base64::decode_b64( $encoded ); die( "Something went wrong: $HTTP::Promise::Stream::Base64::Base64Error\n" if( !defined( $decoded ) ); print( "Decoded data is: $decoded\n" );
This takes the same 2 arguments used in "encode": an input and an output. Each one can be either a file path, a file handle, or a scalar reference.
my $encoded = HTTP::Promise::Stream::Base64::encode_b64( $data ); die( "Something went wrong: $HTTP::Promise::Stream::Base64::Base64Error\n" if( !defined( $encoded ) ); print( "Encoded data is: $encoded\n" );
Jacques Deguest <jack@deguest.jp>
W3C
caniuse
PerlIO::via::Base64
HTTP::Promise, HTTP::Promise::Request, HTTP::Promise::Response, HTTP::Promise::Message, HTTP::Promise::Entity, HTTP::Promise::Headers, HTTP::Promise::Body, HTTP::Promise::Body::Form, HTTP::Promise::Body::Form::Data, HTTP::Promise::Body::Form::Field, HTTP::Promise::Status, HTTP::Promise::MIME, HTTP::Promise::Parser, HTTP::Promise::IO, HTTP::Promise::Stream, HTTP::Promise::Exception
Copyright(c) 2022 DEGUEST Pte. Ltd.
All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install HTTP::Promise, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::Promise
CPAN shell
perl -MCPAN -e shell install HTTP::Promise
For more information on module installation, please visit the detailed CPAN module installation guide.