Skip to content

Commit

Permalink
Merge pull request #1218 from matrix-org/doug/4479_media_size_selection
Browse files Browse the repository at this point in the history
Add a fileSizeToString method using NSByteCountFormatter.
  • Loading branch information
pixlwave authored Sep 7, 2021
2 parents e1c91e0 + 03f8f5f commit 9a946d3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions MatrixSDK/Utils/MXTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ FOUNDATION_EXPORT NSString *const kMXToolsRegexStringForMatrixGroupIdentifier;
*/
+ (long long)roundFileSize:(long long)filesize;

/**
Return file size in string format using `NSByteCountFormatter`.
@param fileSize the file size in bytes.
*/
+ (NSString*)fileSizeToString:(long)fileSize;

/**
Return file size in string format.
Expand Down
11 changes: 11 additions & 0 deletions MatrixSDK/Utils/MXTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,17 @@ + (long long)roundFileSize:(long long)filesize
return roundedFileSize;
}

+ (NSString*)fileSizeToString:(long)fileSize
{
if (fileSize < 0)
{
return @"";
}

NSByteCountFormatter *formatter = [NSByteCountFormatter new];
return [formatter stringFromByteCount:fileSize];
}

+ (NSString*)fileSizeToString:(long)fileSize round:(BOOL)round
{
if (fileSize < 0)
Expand Down
1 change: 1 addition & 0 deletions changelog.d/4479.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MXTools: Add fileSizeToString function that uses NSByteCountFormatter.

0 comments on commit 9a946d3

Please sign in to comment.