summaryrefslogtreecommitdiffstats
path: root/lib/private/largefilehelper.php
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@owncloud.com>2014-02-15 23:21:23 +0100
committerAndreas Fischer <bantu@owncloud.com>2014-05-29 16:26:01 +0200
commit2c36a4b07a088bca4f20c2f6386765dfc8ad07b7 (patch)
tree16f27fe03c0c6213c7aa5cbcb74c3deca8519cb6 /lib/private/largefilehelper.php
parent82e17155bf11161a4f86a4d23872ebee753d63e2 (diff)
downloadnextcloud-server-2c36a4b07a088bca4f20c2f6386765dfc8ad07b7.tar.gz
nextcloud-server-2c36a4b07a088bca4f20c2f6386765dfc8ad07b7.zip
Add helper method for turning int|float into base-10 unsigned integer string.
Diffstat (limited to 'lib/private/largefilehelper.php')
-rw-r--r--lib/private/largefilehelper.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/private/largefilehelper.php b/lib/private/largefilehelper.php
index 5f5e14aca35..66626b4a7fe 100644
--- a/lib/private/largefilehelper.php
+++ b/lib/private/largefilehelper.php
@@ -13,6 +13,30 @@ namespace OC;
*/
class LargeFileHelper {
/**
+ * @brief Formats a signed integer or float as an unsigned integer base-10
+ * string. Passed strings will be checked for being base-10.
+ *
+ * @param int|float|string $number Number containing unsigned integer data
+ *
+ * @return string Unsigned integer base-10 string
+ */
+ public function formatUnsignedInteger($number) {
+ if (is_float($number)) {
+ // Undo the effect of the php.ini setting 'precision'.
+ return number_format($number, 0, '', '');
+ } else if (is_string($number) && ctype_digit($number)) {
+ return $number;
+ } else if (is_int($number)) {
+ // Interpret signed integer as unsigned integer.
+ return sprintf('%u', $number);
+ } else {
+ throw new \UnexpectedValueException(
+ 'Expected int, float or base-10 string'
+ );
+ }
+ }
+
+ /**
* @brief Tries to get the filesize of a file via various workarounds that
* even work for large files on 32-bit platforms.
*