1# @ohos.file.storageStatistics (Application Storage Statistics) 2 3The **storageStatistics** module provides APIs for obtaining storage space information, including the space of built-in and plug-in memory cards, space occupied by different types of data, and space of application data. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```ts 12import { storageStatistics } from '@kit.CoreFileKit'; 13``` 14 15## storageStatistics.getCurrentBundleStats<sup>9+</sup> 16 17getCurrentBundleStats(): Promise<BundleStats> 18 19Obtains the storage space of this application, in bytes. This API uses a promise to return the result. 20 21**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 22 23**Return value** 24 25 | Type | Description | 26 | ------------------------------------------ | -------------------------- | 27 | Promise<[Bundlestats](#bundlestats9)> | Promise used to return the application storage space obtained. | 28 29**Error codes** 30 31For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 32 33| ID| Error Message| 34| -------- | -------- | 35| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. | 36| 13600001 | IPC error. | 37| 13900042 | Unknown error. | 38 39**Example** 40 41 ```ts 42 import { BusinessError } from '@kit.BasicServicesKit'; 43 storageStatistics.getCurrentBundleStats().then((BundleStats: storageStatistics.BundleStats) => { 44 console.info("getCurrentBundleStats successfully:" + JSON.stringify(BundleStats)); 45 }).catch((err: BusinessError) => { 46 console.error("getCurrentBundleStats failed with error:"+ JSON.stringify(err)); 47 }); 48 ``` 49 50## storageStatistics.getCurrentBundleStats<sup>9+</sup> 51 52getCurrentBundleStats(callback: AsyncCallback<BundleStats>): void 53 54Obtains the storage space of this application, in bytes. This API uses an asynchronous callback to return the result. 55 56**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 57 58**Parameters** 59 60 | Name | Type | Mandatory | Description | 61 | -------- | --------------------------------------------------------- | ---- | ------------------------------------ | 62 | callback | AsyncCallback<[BundleStats](#bundlestats9)> | Yes | Callback used to return the application space obtained. | 63 64**Error codes** 65 66For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 67 68| ID| Error Message| 69| -------- | -------- | 70| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. | 71| 13600001 | IPC error. | 72| 13900042 | Unknown error. | 73 74**Example** 75 76 ```ts 77 import { BusinessError } from '@kit.BasicServicesKit'; 78 storageStatistics.getCurrentBundleStats((error: BusinessError, bundleStats: storageStatistics.BundleStats) => { 79 if (error) { 80 console.error("getCurrentBundleStats failed with error:" + JSON.stringify(error)); 81 } else { 82 // Do something. 83 console.info("getCurrentBundleStats successfully:" + JSON.stringify(bundleStats)); 84 } 85 }); 86 ``` 87 88## BundleStats<sup>9+</sup> 89 90**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 91 92| Name | Type | Mandatory| Description | 93| --------- | ------ | --- | -------------- | 94| appSize | number | Yes| Size of the application (excluding empty folders), in bytes. | 95| cacheSize | number | Yes| Size of the cache data, in bytes. | 96| dataSize | number | Yes| Total size of the application, in bytes.| 97