BlobBuilder

  • 版本网址缩略名: DOM/BlobBuilder
  • 版本标题: BlobBuilder
  • 版本 id: 342505
  • 创建于:
  • 创建者: ziyunfei
  • 是否是当前版本?
  • 评论

修订内容

{{ deprecated_header() }}

{{ SeeCompatTable() }}

The BlobBuilder interface provides an easy way to construct {{ domxref("Blob") }} objects. Just create a BlobBuilder 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.

注:BlobBuilder接口已经废弃,请使用新版草案中引入的 {{domxref('Blob') }}构造函数.

方法概述

void append(in ArrayBuffer data);
void append(in Blob data);
void append(in String data, [optional] in String endings);
Blob getBlob([optional] in DOMString contentType);
File getFile(in DOMString name, [optional] in DOMString contentType);

方法

append()

Appends the contents of the specified JavaScript object to the {{ domxref("Blob") }} being built. If the value you specify isn't a {{ domxref("Blob") }}, ArrayBuffer, or String, the value is coerced to a string before being appended to the blob.

void append(
  in ArrayBuffer data
);

void append(
  in Blob data
);


void append(
  in String data,
  [optional] in String endings
);
参数
data
The data to append to the {{ domxref("Blob") }} being constructed.
endings
Specifies how strings containing \n are to be written out. This can be "transparent" (endings unchanged) or "native" (endings changed to match host OS filesystem convention). The default value is "transparent".

getBlob()

Returns the {{ domxref("Blob") }} object that has been constructed using the data passed through calls to {{ manch("append") }}.

Blob getBlob(
  in DOMString contentType {{ optional_inline() }}
);
参数
contentType {{ optional_inline() }}
The MIME type of the data to be returned in the {{ domxref("Blob") }}. This will be the value of the Blob object's type property.
返回值

A {{ domxref("Blob") }} object containing all of the data passed to any calls to {{ manch("append") }} made since the BlobBuilder was created. This also resets the BlobBuilder so that the next call to {{ manch("append") }} is starting a new, empty blob.

getFile() {{ non-standard_inline() }}

返回一个{{ domxref("File") }}对象.

File getFile(
  in DOMString name,
  [optional] in DOMString contentType
); 
参数
name
文件名.
contentType {{ optional_inline() }}
设置返回的{{ domxref("File") }}对象中的数据的MIME类型.这个值将会成为返回的File对象的type属性的值.
返回值

一个{{ domxref("File") }}对象.

浏览器兼容性

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 8
As WebKitBlobBuilder
{{ CompatGeckoDesktop("6.0") }}
As MozBlobBuilder
10
As MSBlobBuilder
{{ CompatNo() }} {{ CompatNo() }}†
getfile() {{ non-standard_inline() }} {{ CompatNo() }} {{ CompatGeckoDesktop("8.0") }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 3
As WebKitBlobBuilder
{{ CompatGeckoMobile("6.0") }}
As MozBlobBuilder
{{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}
getfile() {{ non-standard_inline() }} {{ CompatNo() }} {{ CompatGeckoMobile("8.0") }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}

注:BlobBuilder已被废弃

  • 从Firefox 14开始,使用MozBlobBuilder会在Web控制台显示一条警告消息: MozBlobBuilder已被废弃,请使用{{ domxref("Blob") }}来代替.
  • 从Firefox 18开始,MozBlobBuilder已被删除.
  • WebKit has deprecated WebKitBlobBuilder 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 WebKit changeset for details).

相关链接

  • {{ spec("http://dev.w3.org/2009/dap/file-system/file-writer.html#idl-def-BlobBuilder", "File API Specification: BlobBuilder", "ED") }}
  • {{ domxref("Blob") }}
  • {{ domxref("File") }}

修订版来源

<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=".E6.96.B9.E6.B3.95">方法</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=".E5.8F.82.E6.95.B0">参数</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="Parameters">参数</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="Return_value">返回值</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()_.7B.7B_non-standard_inline()_.7D.7D">getFile() {{ non-standard_inline() }}</h3>
<p>返回一个{{ domxref("File") }}对象.</p>
<pre class="eval">
File getFile(
  in DOMString name,
  [optional] in DOMString contentType
); 
</pre>
<h6 id=".E5.8F.82.E6.95.B0">参数</h6>
<dl>
  <dt>
    name</dt>
  <dd>
    文件名.</dd>
  <dt>
    contentType {{ optional_inline() }}</dt>
  <dd>
    设置返回的{{ domxref("File") }}对象中的数据的MIME类型.这个值将会成为返回<code>的File</code>对象的type属性的值.</dd>
</dl>
<h6 id=".E8.BF.94.E5.9B.9E.E5.80.BC">返回值</h6>
<p>一个{{ domxref("File") }}对象.</p>
<h2 id=".E6.B5.8F.E8.A7.88.E5.99.A8.E5.85.BC.E5.AE.B9.E6.80.A7">浏览器兼容性</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=".E6.B3.A8.3ABlobBuilder.E5.B7.B2.E8.A2.AB.E5.BA.9F.E5.BC.83">注: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=".E7.9B.B8.E5.85.B3.E9.93.BE.E6.8E.A5">相关链接</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>
恢复到这个版本