Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a fileSizeToString method using NSByteCountFormatter. #1218

Merged
merged 3 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.