Skip to content

Commit

Permalink
refs #1067 : added - Base64Stream utils
Browse files Browse the repository at this point in the history
 -
  • Loading branch information
inureyes committed Jan 8, 2015
1 parent b72ddf1 commit b2934e7
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions framework/utils/Base64Stream.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/// Copyright (c) 2004-2015, Needlworks / Tatter Network Foundation
/// All rights reserved. Licensed under the GPL.
/// See the GNU General Public License for more details. (/documents/LICENSE, /documents/COPYRIGHT)
class Utils_Base64Stream {
function encode($src = null, $dest = null) {
if (is_string($src)) {
if (is_null($dest)) {
if (!$src = fopen($src, 'r'))
return false;
while (!feof($src))
echo base64_encode(fread($src, 3 * 1024));
fclose($src);
return true;
} else if (is_a($dest, 'Utils_OutputWriter')) {
if (!$src = fopen($src, 'r'))
return false;
while (!feof($src))
$dest->write(base64_encode(fread($src, 3 * 1024)));
fclose($src);
return true;
}
}
return false;
}

function decode($src = null, $dest = null) {
if (is_resource($src) && (get_resource_type($src) == 'stream')) {
if (is_string($dest)) {
$dest = fopen($dest, 'w');
fseek($src, 0);
while (!feof($src))
fwrite($dest, base64_decode(trim(fread($src, 3 * 1024))));
fclose($dest);
return true;
}
}
return false;
}
}
?>

0 comments on commit b2934e7

Please sign in to comment.