1e41f4b71Sopenharmony_ci# @ohos.file.storageStatistics (应用空间统计)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci该模块提供空间查询相关的常用功能:包括对内外卡的空间查询,对应用分类数据统计的查询,对应用数据的查询等。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## 导入模块
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci```ts
12e41f4b71Sopenharmony_ciimport  { storageStatistics } from '@kit.CoreFileKit';
13e41f4b71Sopenharmony_ci```
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## storageStatistics.getCurrentBundleStats<sup>9+</sup>
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_cigetCurrentBundleStats(): Promise&lt;BundleStats&gt;
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci第三方应用异步获取当前应用存储空间大小(单位为Byte),以Promise方式返回。
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**返回值:**
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci  | 类型                                        | 说明                       |
26e41f4b71Sopenharmony_ci  | ------------------------------------------ | -------------------------- |
27e41f4b71Sopenharmony_ci  | Promise&lt;[Bundlestats](#bundlestats9)&gt; | Promise对象,返回指定卷上的应用存储空间大小(单位为Byte)      |
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**错误码:**
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
34e41f4b71Sopenharmony_ci| -------- | -------- |
35e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. |
36e41f4b71Sopenharmony_ci| 13600001 | IPC error. |
37e41f4b71Sopenharmony_ci| 13900042 | Unknown error. |
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci**示例:**
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci  ```ts
42e41f4b71Sopenharmony_ci  import { BusinessError } from '@kit.BasicServicesKit';
43e41f4b71Sopenharmony_ci  storageStatistics.getCurrentBundleStats().then((BundleStats: storageStatistics.BundleStats) => {
44e41f4b71Sopenharmony_ci    console.info("getCurrentBundleStats successfully:" + JSON.stringify(BundleStats));
45e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
46e41f4b71Sopenharmony_ci    console.error("getCurrentBundleStats failed with error:"+ JSON.stringify(err));
47e41f4b71Sopenharmony_ci  });
48e41f4b71Sopenharmony_ci  ```
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci## storageStatistics.getCurrentBundleStats<sup>9+</sup>
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_cigetCurrentBundleStats(callback: AsyncCallback&lt;BundleStats&gt;): void
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci第三方应用异步获取当前应用存储空间大小(单位为Byte),以callback方式返回。
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci**参数:**
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci  | 参数名    | 类型                                                       | 必填  | 说明                                 |
61e41f4b71Sopenharmony_ci  | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
62e41f4b71Sopenharmony_ci  | callback | AsyncCallback&lt;[BundleStats](#bundlestats9)&gt;          | 是   | 获取指定卷上的应用存储空间大小之后的回调        |
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci**错误码:**
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
69e41f4b71Sopenharmony_ci| -------- | -------- |
70e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. |
71e41f4b71Sopenharmony_ci| 13600001 | IPC error. |
72e41f4b71Sopenharmony_ci| 13900042 | Unknown error. |
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**示例:**
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci  ```ts
77e41f4b71Sopenharmony_ci  import { BusinessError } from '@kit.BasicServicesKit';
78e41f4b71Sopenharmony_ci  storageStatistics.getCurrentBundleStats((error: BusinessError, bundleStats: storageStatistics.BundleStats) => {
79e41f4b71Sopenharmony_ci    if (error) {
80e41f4b71Sopenharmony_ci      console.error("getCurrentBundleStats failed with error:" + JSON.stringify(error));
81e41f4b71Sopenharmony_ci    } else {
82e41f4b71Sopenharmony_ci      // do something
83e41f4b71Sopenharmony_ci      console.info("getCurrentBundleStats successfully:" + JSON.stringify(bundleStats));
84e41f4b71Sopenharmony_ci    }
85e41f4b71Sopenharmony_ci  });
86e41f4b71Sopenharmony_ci  ```
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci## BundleStats<sup>9+</sup>
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci| 名称      | 类型   | 必填 | 说明           |
93e41f4b71Sopenharmony_ci| --------- | ------ | --- | -------------- |
94e41f4b71Sopenharmony_ci| appSize   | number | 是 | app数据大小(不包含空目录)(单位为Byte)    |
95e41f4b71Sopenharmony_ci| cacheSize | number | 是 | 缓存数据大小(单位为Byte)   |
96e41f4b71Sopenharmony_ci| dataSize  | number | 是 | 应用总数据大小(单位为Byte) |
97