Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
2c36a4b0
Commit
2c36a4b0
authored
11 years ago
by
Andreas Fischer
Browse files
Options
Downloads
Patches
Plain Diff
Add helper method for turning int|float into base-10 unsigned integer string.
parent
82e17155
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/private/largefilehelper.php
+24
-0
24 additions, 0 deletions
lib/private/largefilehelper.php
tests/lib/largefilehelper.php
+46
-0
46 additions, 0 deletions
tests/lib/largefilehelper.php
with
70 additions
and
0 deletions
lib/private/largefilehelper.php
+
24
−
0
View file @
2c36a4b0
...
@@ -12,6 +12,30 @@ namespace OC;
...
@@ -12,6 +12,30 @@ namespace OC;
* Helper class for large files on 32-bit platforms.
* Helper class for large files on 32-bit platforms.
*/
*/
class
LargeFileHelper
{
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
* @brief Tries to get the filesize of a file via various workarounds that
* even work for large files on 32-bit platforms.
* even work for large files on 32-bit platforms.
...
...
This diff is collapsed.
Click to expand it.
tests/lib/largefilehelper.php
0 → 100644
+
46
−
0
View file @
2c36a4b0
<?php
/**
* Copyright (c) 2014 Andreas Fischer <bantu@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace
Test
;
class
LargeFileHelper
extends
\PHPUnit_Framework_TestCase
{
protected
$helper
;
public
function
setUp
()
{
parent
::
setUp
();
$this
->
helper
=
new
\OC\LargeFileHelper
;
}
public
function
testFormatUnsignedIntegerFloat
()
{
$this
->
assertSame
(
'9007199254740992'
,
$this
->
helper
->
formatUnsignedInteger
((
float
)
9007199254740992
)
);
}
public
function
testFormatUnsignedIntegerInt
()
{
$this
->
assertSame
(
PHP_INT_SIZE
===
4
?
'4294967295'
:
'18446744073709551615'
,
$this
->
helper
->
formatUnsignedInteger
(
-
1
)
);
}
public
function
testFormatUnsignedIntegerString
()
{
$this
->
assertSame
(
'9007199254740993'
,
$this
->
helper
->
formatUnsignedInteger
(
'9007199254740993'
)
);
}
/**
* @expectedException \UnexpectedValueException
*/
public
function
testFormatUnsignedIntegerStringException
()
{
$this
->
helper
->
formatUnsignedInteger
(
'900ABCD254740993'
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment