aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/api/blob/slice/index.html
blob: a6f44cfebdb5ead4e43508e0db59102a22e86eff (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
---
title: Blob.slice()
slug: Web/API/Blob/slice
translation_of: Web/API/Blob/slice
---
<div>{{APIRef("File API")}}</div>

<p>O método <strong><code>Blob.slice()</code></strong> é usado para criar um novo {{domxref("Blob")}} object  <span lang="pt">contendo os dados no intervalo especificado de bytes da fonte </span>{{domxref("Blob")}}.</p>

<div class="note"><span lang="pt">Nota: Esteja ciente de que o método <code>slice ()</code> tem prefixos de fornecedores em alguns navegadores e versões: <code>blob.mozSlice ()</code> para Firefox 12 e anteriores e <code>blob.webkitSlice ()</code> no Safari. Uma versão antiga do método <code>slice ()</code>, sem prefixos de fornecedor, tinha uma semântica diferente e é obsoleta</span></div>

<h2 id="Sintaxe">Sintaxe</h2>

<pre class="syntaxbox">let blob = instanceOfBlob.slice([start [, end [, contentType]]]);</pre>

<h3 id="Parâmetros">Parâmetros</h3>

<dl>
 <dt><code>start</code> {{optional_inline}}</dt>
 <dd>An index into the {{domxref("Blob")}} indicating the first byte to include in the new {{domxref("Blob")}}. If you specify a negative value, it's treated as an offset from the end of the string toward the beginning. For example, -10 would be the 10th from last byte in the {{domxref("Blob")}}. The default value is 0. If you specify a value for <code>start</code> that is larger than the size of the source {{domxref("Blob")}}, the returned {{domxref("Blob")}} has size 0 and contains no data.</dd>
 <dt><code>end</code> {{optional_inline}}</dt>
 <dd>An index into the {{domxref("Blob")}} indicating the first byte that will *not* be included in the new {{domxref("Blob")}} (i.e. the byte exactly at this index is not included). If you specify a negative value, it's treated as an offset from the end of the string toward the beginning. For example, -10 would be the 10th from last byte in the {{domxref("Blob")}}. The default value is <code>size</code>.</dd>
 <dt><code>contentType</code> {{optional_inline}}</dt>
 <dd>The content type to assign to the new {{domxref("Blob")}}; this will be the value of its <code>type</code> property. The default value is an empty string.</dd>
</dl>

<h3 id="Return_value">Return value</h3>

<p>A new {{domxref("Blob")}} object containing the specified data from the source {{domxref("Blob")}}.</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th>Specification</th>
   <th>Status</th>
   <th>Comment</th>
  </tr>
  <tr>
   <td>{{SpecName("File API", "#dfn-slice", "Blob.slice()")}}</td>
   <td>{{Spec2("File API")}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Edge</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>10 {{property_prefix("webkit")}} [1]<br>
    21</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>5 {{property_prefix("moz")}} [1]<br>
    13 [2]</td>
   <td>10</td>
   <td>12 [1]</td>
   <td>5.1 {{property_prefix("webkit")}} [3]</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Edge</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoMobile("13.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] The <code>slice()</code> method had initially taken <code>length</code> as the second argument to indicate the number of bytes to include in the new <code>Blob</code>. If you specified values such that <code>start + length</code> exceeded the size of the source <code>Blob</code>, the returned <code>Blob</code> contained data from the start index to the end of the source <code>Blob</code>. That version of the <code>slice()</code> was implemented in <a href="https://hg.mozilla.org/mozilla-central/rev/1b3947ed93c6">Firefox 4</a>, <a href="http://trac.webkit.org/changeset/55670">WebKit</a>, and <a href="http://www.opera.com/docs/specs/presto28/file/#blob">Opera 11.10</a>. However, since that syntax is differed from <a href="/en-US/JavaScript/Reference/Global_Objects/Array/slice"><code>Array.slice()</code></a> and <a href="/en-US/JavaScript/Reference/Global_Objects/String/slice"><code>String.slice()</code></a>, Gecko and WebKit removed support and added support for the new syntax as <code>Blob.slice()</code>/<a href="http://trac.webkit.org/changeset/83873"><code>Blob.webkitSlice</code></a>.</p>

<p>[2] Prior to Gecko 12.0 {{geckoRelease("12.0")}}, there was a bug that affected the behavior of <code>Blob.slice()</code>; it did not work for <code>start</code> and end positions outside the range of signed 64-bit values; it has now been fixed to support unsigned 64-bit values.</p>

<p>[3] This was implemented in <a href="http://trac.webkit.org/changeset/83873">534.29</a>.</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{domxref("Blob")}}</li>
 <li>{{domxref("BlobBuilder")}}</li>
</ul>