BlobBuilder

不推荐

这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀.由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变.

The BlobBuilder interface provides an easy way to construct Blob objects. Just create a BlobBuilder and append chunks of data to it by calling the append() method. When you're done building your blob, call getBlob() to retrieve a Blob containing the data you sent into the blob builder.

注:BlobBuilder接口已经废弃,请使用新版草案中引入的 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 Blob being built. If the value you specify isn't a 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 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 Blob object that has been constructed using the data passed through calls to append().

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

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

getFile()

返回一个File对象.

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

一个File对象.

浏览器兼容性

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 8
As WebKitBlobBuilder
6.0 (6.0)
As MozBlobBuilder
10
As MSBlobBuilder
Not supported Not supported
getfile() Not supported 8.0 (8.0) Not supported Not supported Not supported
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 3
As WebKitBlobBuilder
6.0 (6.0)
As MozBlobBuilder
Not supported Not supported Not supported
getfile() Not supported 8.0 (8.0) Not supported Not supported Not supported

注:BlobBuilder已被废弃

  • 从Firefox 14开始,使用MozBlobBuilder会在Web控制台显示一条警告消息: MozBlobBuilder已被废弃,请使用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).

相关链接

文档标签和贡献者