-
Notifications
You must be signed in to change notification settings - Fork 467
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
Retrieve the total size of the data stored in Async Storage #336
Comments
It would be great. |
This issue has been marked as stale due to inactivity. Please respond or otherwise resolve the issue within 7 days or it will be closed. |
@ziyaddin @gusilveiramp I wanted to know the size of storage I was using on iOS, in case you still want to know the code below does the job, you'll just need to expose the native method. It returns the amount of storage used in Bytes -(NSString *)_getSize
{
NSString* directory = RCTGetStorageDirectory();
NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directory error:nil];
NSEnumerator *contentsEnumurator = [contents objectEnumerator];
NSString *file;
unsigned long long int folderSize = 0;
while (file = [contentsEnumurator nextObject]) {
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[directory stringByAppendingPathComponent:file] error:nil];
folderSize += [[fileAttributes objectForKey:NSFileSize] intValue];
}
NSString *sizeStr = [NSString stringWithFormat:@"%llu", folderSize];
return sizeStr;
} EDIT: Also find the code below for Android, as above it returns the storage used in bytes: File f = new File(mReactDatabaseSupplier.get().getPath());
long dbSize = f.length(); |
is there a way to get total size of the data for android ??? |
This should do it, based of this SO answer: https://stackoverflow.com/questions/6364577/how-to-get-the-current-sqlite-database-size-or-package-size-in-android/52191503 File f = new File(mReactDatabaseSupplier.get().getPath());
long dbSize = f.length(); |
Anyone have a handy way to do this from the JS side of things? |
@isaachinman I put this together while searching for an answer to this question. It seems to be working well enough.
And then in your root component:
|
Motivation
In some cases, it is important to know the current total size of the data stored in Async Storage. It would help to predict possible storage issues beforehand due to the storage limit set by React Native authors.
Description
Described in "Motivation" section.
New feature implementation
Possible methods in my mind:
The text was updated successfully, but these errors were encountered: