Because BlobBuilder is deprecated, we have to use Blob, so instead of
var bb = new (window.MozBlobBuilder || window.WebKitBlobBuilder || window.BlobBuilder)();
bb.append(data);
var blob = bb.getBlob();
We do
var blob = new Blob([data]);
That is ok, but what if I want to append Data to same blob more times? Something like:
for(var i=0;i<10;i++){
bb.append(" "+i);
}
How to do it without BlobBuilder? Thanks all!
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);
In the browser, there are additional higher-level objects, described in File API, in particular Blob. Blob consists of an optional string type (a MIME-type usually), plus blobParts – a sequence of other Blob objects, strings and BufferSource.
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.
The storage service offers three types of blobs, block blobs, append blobs, and page blobs. You specify the blob type when you create the blob. Once the blob has been created, its type cannot be changed, and it can be updated only by using operations appropriate for that blob type, i.e.,...
Thanks to minitech♦!
You answer moved me to answer my question. So what you show is again working with a variable and at the end write it to blob. I wanted so said update a blob, or with other words append to blob. So you can do it on this way:
var blob = new Blob([], {type: "text/plain"});
for (var i=0; i<10; i++){
blob = new Blob([blob," "+i], {type: "text/plain"});
}
Here is Fiddle: http://jsfiddle.net/yuM2N/111/
[data]
is an array of parts, so you can just append to an array:
var parts = [];
for (var i = 0; i < 10; i++) {
parts.push(" " + i);
}
var blob = new Blob(parts);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With