aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/blobbuilder/index.html
blob: 03248ac1e545c5ace9998219cf29d6fef5d6eab8 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
---
title: BlobBuilder
slug: Web/API/BlobBuilder
translation_of: Web/API/BlobBuilder
---
<p>{{ deprecated_header() }}</p>
<p>{{ SeeCompatTable() }}</p>
<p>The <code>BlobBuilder</code> interface provides an easy way to construct {{ domxref("Blob") }} objects. Just create a <code>BlobBuilder</code> and append chunks of data to it by calling the {{ manch("append") }} method. When you're done building your blob, call {{ manch("getBlob") }} to retrieve a {{ domxref("Blob") }} containing the data you sent into the blob builder.</p>
<div class="note">
  <strong>注:</strong><code>BlobBuilder</code>接口已经废弃,请使用新版草案中引入的 {{domxref('Blob') }}构造函数.</div>
<h2 id="Method_overview" name="Method_overview">方法概述</h2>
<table class="standard-table">
  <tbody>
    <tr>
      <td><code>void <a href="/zh-CN/DOM/BlobBuilder#append()" title="zh-CN/DOM/BlobBuilder#append()">append</a>(in ArrayBuffer data);</code></td>
    </tr>
    <tr>
      <td><code>void <a href="/zh-CN/DOM/BlobBuilder#append()" title="zh-CN/DOM/BlobBuilder#append()">append</a>(in Blob data);</code></td>
    </tr>
    <tr>
      <td><code>void <a href="/zh-CN/DOM/BlobBuilder#append()" title="zh-CN/DOM/BlobBuilder#append()">append</a>(in String data, [optional] in String endings);</code></td>
    </tr>
    <tr>
      <td><code>Blob <a href="/zh-CN/DOM/BlobBuilder#getBlob()" title="zh-CN/DOM/BlobBuilder#getBlob()">getBlob</a>([optional] in DOMString contentType);</code></td>
    </tr>
    <tr>
      <td><code>File <a href="/zh-CN/DOM/BlobBuilder#getFile()" title="zh-CN/DOM/BlobBuilder#getFile()">getFile</a>(in DOMString name, [optional] in DOMString contentType);</code></td>
    </tr>
  </tbody>
</table>
<h2 id="方法">方法</h2>
<h3 id="append()">append()</h3>
<p>Appends the contents of the specified JavaScript object to the {{ domxref("Blob") }} being built. If the value you specify isn't a {{ domxref("Blob") }}, <a href="/zh-CN/JavaScript_typed_arrays/ArrayBuffer" title="zh-CN/JavaScript typed arrays/Arraybuffer"><code>ArrayBuffer</code></a>, or <a href="/zh-CN/JavaScript/Reference/Global_Objects/String" title="zh-CN/JavaScript/Reference/Global Objects/String"><code>String</code></a>, the value is coerced to a string before being appended to the blob.</p>
<pre>void append(
  in ArrayBuffer data
);

void append(
  in Blob data
);


void append(
  in String data,
  [optional] in String endings
);
</pre>
<h6 id="参数">参数</h6>
<dl>
  <dt>
    <code>data</code></dt>
  <dd>
    The data to append to the {{ domxref("Blob") }} being constructed.</dd>
  <dt>
    <code>endings</code></dt>
  <dd>
    Specifies how strings containing <code>\n</code> are to be written out. This can be <code>"transparent"</code> (endings unchanged) or <code>"native"</code> (endings changed to match host OS filesystem convention). The default value is <code>"transparent"</code>.</dd>
</dl>
<h3 id="getBlob()">getBlob()</h3>
<p>Returns the {{ domxref("Blob") }} object that has been constructed using the data passed through calls to {{ manch("append") }}.</p>
<pre class="eval">Blob getBlob(
  in DOMString contentType {{ optional_inline() }}
);
</pre>
<h6 id="参数_2">参数</h6>
<dl>
  <dt>
    contentType {{ optional_inline() }}</dt>
  <dd>
    The MIME type of the data to be returned in the {{ domxref("Blob") }}. This will be the value of the <code>Blob</code> object's type property.</dd>
</dl>
<h6 id="返回值">返回值</h6>
<p>A {{ domxref("Blob") }} object containing all of the data passed to any calls to {{ manch("append") }} made since the <code>BlobBuilder</code> was created. This also resets the <code>BlobBuilder</code> so that the next call to {{ manch("append") }} is starting a new, empty blob.</p>
<h3 id="getFile()_non-standard_inline()">getFile() {{ non-standard_inline() }}</h3>
<p>返回一个{{ domxref("File") }}对象.</p>
<pre class="eval">File getFile(
  in DOMString name,
  [optional] in DOMString contentType
);
</pre>
<h6 id="参数_3">参数</h6>
<dl>
  <dt>
    name</dt>
  <dd>
    文件名.</dd>
  <dt>
    contentType {{ optional_inline() }}</dt>
  <dd>
    设置返回的{{ domxref("File") }}对象中的数据的MIME类型.这个值将会成为返回<code>的File</code>对象的type属性的值.</dd>
</dl>
<h6 id="返回值_2">返回值</h6>
<p>一个{{ domxref("File") }}对象.</p>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>8<br>
          As <code>WebKitBlobBuilder</code></td>
        <td>{{ CompatGeckoDesktop("6.0") }}<br>
          As <code>MozBlobBuilder</code></td>
        <td>10<br>
          As <code>MSBlobBuilder</code></td>
        <td>{{ CompatNo() }}</td>
        <td>{{ CompatNo() }}</td>
      </tr>
      <tr>
        <td><code>getfile()</code> {{ non-standard_inline() }}</td>
        <td>{{ CompatNo() }}</td>
        <td>{{ CompatGeckoDesktop("8.0") }}</td>
        <td>{{ CompatNo() }}</td>
        <td>{{ CompatNo() }}</td>
        <td>{{ CompatNo() }}</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Mobile</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>3<br>
          As <code>WebKitBlobBuilder</code></td>
        <td>{{ CompatGeckoMobile("6.0") }}<br>
          As <code>MozBlobBuilder</code></td>
        <td>{{ CompatNo() }}</td>
        <td>{{ CompatNo() }}</td>
        <td>{{ CompatNo() }}</td>
      </tr>
      <tr>
        <td><code>getfile()</code> {{ non-standard_inline() }}</td>
        <td>{{ CompatNo() }}</td>
        <td>{{ CompatGeckoMobile("8.0") }}</td>
        <td>{{ CompatNo() }}</td>
        <td>{{ CompatNo() }}</td>
        <td>{{ CompatNo() }}</td>
      </tr>
    </tbody>
  </table>
</div>
<h3 id="注BlobBuilder已被废弃">注:BlobBuilder已被废弃</h3>
<ul>
  <li>从Firefox 14开始,使用<code>MozBlobBuilder</code>会在Web控制台显示一条警告消息: <code>MozBlobBuilder</code>已被废弃,请使用{{ domxref("Blob") }}来代替.</li>
  <li>从Firefox 18开始,<code>MozBlobBuilder</code>已被删除.</li>
  <li>WebKit has deprecated <code>WebKitBlobBuilder</code> and has made its support configurable. Currently Safari disables the feature in Nightly, so it will never likely to ship in the final version. On the other hand, Chrome, which has supported it since Chrome 8, still enables the feature. So Chrome might continue to support the feature. (See this <a class="external" href="http://trac.webkit.org/changeset/115666" title="http://trac.webkit.org/changeset/115666">WebKit changeset</a> for details).</li>
</ul>
<h2 id="相关链接">相关链接</h2>
<ul>
  <li>{{ spec("http://dev.w3.org/2009/dap/file-system/file-writer.html#idl-def-BlobBuilder", "File API Specification: BlobBuilder", "ED") }}</li>
  <li>{{ domxref("Blob") }}</li>
  <li>{{ domxref("File") }}</li>
</ul>