1# @ohos.file.storageStatistics (应用空间统计)
2
3该模块提供空间查询相关的常用功能:包括对内外卡的空间查询,对应用分类数据统计的查询,对应用数据的查询等。
4
5> **说明:**
6>
7> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9## 导入模块
10
11```ts
12import  { storageStatistics } from '@kit.CoreFileKit';
13```
14
15## storageStatistics.getCurrentBundleStats<sup>9+</sup>
16
17getCurrentBundleStats(): Promise&lt;BundleStats&gt;
18
19应用异步获取当前应用存储空间大小(单位为Byte),以Promise方式返回。
20
21**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
22
23**返回值:**
24
25  | 类型                                        | 说明                       |
26  | ------------------------------------------ | -------------------------- |
27  | Promise&lt;[Bundlestats](#bundlestats9)&gt; | Promise对象,返回指定卷上的应用存储空间大小(单位为Byte)      |
28
29**错误码:**
30
31以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
32
33| 错误码ID | 错误信息 |
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**示例:**
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&lt;BundleStats&gt;): void
53
54应用异步获取当前应用存储空间大小(单位为Byte),以callback方式返回。
55
56**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
57
58**参数:**
59
60  | 参数名    | 类型                                                       | 必填  | 说明                                 |
61  | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
62  | callback | AsyncCallback&lt;[BundleStats](#bundlestats9)&gt;          | 是   | 获取指定卷上的应用存储空间大小之后的回调        |
63
64**错误码:**
65
66以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
67
68| 错误码ID | 错误信息 |
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**示例:**
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**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
91
92| 名称      | 类型   | 必填 | 说明           |
93| --------- | ------ | --- | -------------- |
94| appSize   | number | 是 | 应用安装文件大小(单位为Byte)    |
95| cacheSize | number | 是 | 应用缓存文件大小(单位为Byte)   |
96| dataSize  | number | 是 | 应用文件存储大小(除应用安装文件和缓存文件)(单位为Byte) |
97