• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * @file
18 * @kit BasicServicesKit
19 */
20
21import { BusinessError } from './@ohos.base';
22
23/**
24 * Cache download capability provider.
25 *
26 * @namespace cacheDownload
27 * @syscap SystemCapability.Request.FileTransferAgent
28 * @since 18
29 */
30declare namespace cacheDownload {
31    /**
32     * Options of the cache download task.
33     *
34     * @typedef CacheDownloadOptions
35     * @syscap SystemCapability.Request.FileTransferAgent
36     * @since 18
37     */
38    interface CacheDownloadOptions {
39        /**
40         * HTTP headers added to the cache download request.
41         *
42         * @type { ?Record<string, string> }
43         * @syscap SystemCapability.Request.FileTransferAgent
44         * @since 18
45         */
46        headers?: Record<string, string>;
47    }
48
49    /**
50     * Downloads resources at the specified URL. Resources will be stored in memory cache or files cache.
51     * The maximum size of the specified URL is 8192 bytes.
52     * The maximum size of a single resource after decompression is 20,971,520 bytes(20 MB).
53     * If the decompressed size of the downloaded resource exceeds the limit, it will not be recorded in the cache.
54     *
55     * @permission ohos.permission.INTERNET
56     * @param { string } url - URL of the cache download target.
57     * @param { CacheDownloadOptions } options - Options of the cache download task.
58     * @throws { BusinessError } 201 - permission denied.
59     * @throws { BusinessError } 401 - parameter error. Possible causes: 1. Missing mandatory parameters.
60     * <br>2. Incorrect parameter type. 3. Parameter verification failed.
61     * @syscap SystemCapability.Request.FileTransferAgent
62     * @since 18
63     */
64    function download(url: string, options: CacheDownloadOptions);
65
66    /**
67     * Cancels an ongoing cache download task based on the target URL.
68     * The maximum size of the specified URL is 8192 bytes.
69     *
70     * @param { string } url - URL of the cache download target.
71     * @throws { BusinessError } 401 - parameter error. Possible causes: 1. Missing mandatory parameters.
72     * <br>2. Incorrect parameter type. 3. Parameter verification failed.
73     * @syscap SystemCapability.Request.FileTransferAgent
74     * @since 18
75     */
76    function cancel(url: string);
77
78    /**
79     * Sets the size of the memory cache used to store downloaded content.
80     * The default size is 0 bytes.
81     * The maximum size is 1,073,741,824 bytes(1 GB).
82     *
83     * @param { number } bytes - The maximum amount of data cached in memory, in bytes.
84     * @throws { BusinessError } 401 - parameter error. Possible causes: 1. Missing mandatory parameters.
85     * <br>2. Incorrect parameter type. 3. Parameter verification failed.
86     * @syscap SystemCapability.Request.FileTransferAgent
87     * @since 18
88     */
89    function setMemoryCacheSize(bytes: number);
90
91    /**
92     * Sets the size of the file cache used to store downloaded content.
93     * The default size is 104,857,600 bytes(100 MB).
94     * The maximum size is 4,294,967,296 bytes(4 GB).
95     *
96     * @param { number } bytes - The maximum amount of data cached in files, in bytes.
97     * @throws { BusinessError } 401 - parameter error. Possible causes: 1. Missing mandatory parameters.
98     * <br>2. Incorrect parameter type. 3. Parameter verification failed.
99     * @syscap SystemCapability.Request.FileTransferAgent
100     * @since 18
101     */
102    function setFileCacheSize(bytes: number);
103}
104
105export default cacheDownload;