aboutsummaryrefslogtreecommitdiff
path: root/files/ru/web/api/storagemanager/estimate/index.html
blob: 0282d75f924ee311dce8d82c7cfed4ae9fbdedbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
---
title: StorageManager.estimate()
slug: Web/API/StorageManager/estimate
tags:
  - метод
translation_of: Web/API/StorageManager/estimate
---
<p>{{securecontext_header}}{{APIRef("Storage")}}</p>

<p>The <strong><code>estimate()</code></strong> method of the {{domxref("StorageManager")}} interface asks the Storage Manager to obtain quota and usage information for the current origin. This method operates asynchronously, so it returns a {{jsxref("Promise")}} which resolves once the information is available. The promise's fulfillment handler receives as an input a {{domxref("StorageEstimate")}} with the usage and quota data.</p>

<h2 id="Синтаксис">Синтаксис</h2>

<pre class="syntaxbox">var <em>estimatePromise</em> = <em>StorageManager</em>.estimate();</pre>

<h3 id="Параметры">Параметры</h3>

<p>None.</p>

<h3 id="Возвращаемый_результат">Возвращаемый результат</h3>

<p>A {{jsxref('Promise')}} that resolves to an object which conforms to the {{domxref('StorageEstimate')}} dictionary. This dictionary contains estimates of how much space is available to the origin or app (in {{domxref("StorageEstimate.quota")}}, as well as how much is currently used (in {{domxref("StorageEstimate.usage")}}). These are not exact numbers; between compression, deduplication, and obfuscation for security reasons, they will not be precise.</p>

<p>You may find that the <code>quota</code> varies from app to app based on factors such as the frequency with which the user visits it, commonly-known site popularity data, and so forth.</p>

<h2 id="Example">Примеры</h2>

<p>In this example, we obtain the usage estimates and present the percentage of storage capacity currently used to the user.</p>

<h3 id="HTML_content">HTML content</h3>

<pre class="brush: html">&lt;p&gt;
  You're currently using about &lt;span id="percent"&gt;
  &lt;/span&gt;% of your available storage.
&lt;/p&gt;
</pre>

<h3 id="JavaScript_content">JavaScript content</h3>

<pre class="brush: js">navigator.storage.estimate().then(function(estimate) {
  document.getElementById("percent").innerHTML =
      (estimate.usage / estimate.quota).toFixed(2);
});
</pre>

<h3 id="Результат">Результат</h3>

<p>{{ EmbedLiveSample('Example', 600, 40) }}</p>

<h2 id="Спецификация">Спецификация</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Спецификация</th>
   <th scope="col">Статус</th>
   <th scope="col">Комментарий</th>
  </tr>
  <tr>
   <td>{{SpecName('Storage','#dom-storagemanager-estimate','estimate()')}}</td>
   <td>{{Spec2('Storage')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Совместимость_с_браузерами">Совместимость с браузерами</h2>

<div>{{Compat("api.StorageManager.estimate")}}</div>

<h2 id="Смотрите_также">Смотрите также</h2>

<ul>
 <li>Storage API</li>
 <li>{{domxref("Storage")}}, the object returned by {{domxref("Window.localStorage")}}</li>
 <li>{{domxref("StorageManager")}}</li>
 <li>{{domxref("navigator.storage")}}</li>
</ul>