Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blob in TypeScript

Tags:

typescript

I am trying to write a file downloader in TypeScript using the FileSystem API.

When I'm trying to create a new Blob object:

var blob: Blob = new Blob(xhr.response, JSON.stringify(mime));

I'm getting the error:

Supplied parameters do not match any signature of call target

It's possible to create a Blob without any parameters:

var blob: Blob = new Blob();

But that doesn't help.

The (deprecated) fall back for Blob is the BlobBuilder object but TypeScript (VS 2012 Plugin) only offers the MSBlobBuilder object.

What am I doing wrong? Or does TypeScript not know about the Blob constructor?

like image 216
Jo David Avatar asked Oct 29 '12 14:10

Jo David


People also ask

What is BLOB used for?

What is BLOB used for? Although they can consist of either structured or unstructured data, BLOBs are mostly used in SQL (Standard Query Language) to store unstructured data files. Because BLOBs are used to store multimedia files, they are often large pieces of data, up to several gigabytes.

What is BLOB example?

BLOB (Binary Large Object) Examples Common BLOB examples are: Video (MP4, MOV) Audio (MP3) Images (JPG, PNG, PDF, RAW)

What is a JavaScript BLOB?

A Blob is an opaque reference to, or handle for, a chunk of data. The name comes from SQL databases, where it means “Binary Large Object.” In JavaScript, Blobs often represent binary data, and they can be large, but neither is required: a Blob could also represent the contents of a small text file.

What is a BLOB image?

A binary large object (BLOB or blob) is a collection of binary data stored as a single entity. Blobs are typically images, audio or other multimedia objects, though sometimes binary executable code is stored as a blob.


1 Answers

The definition for Blob in the lib.d.ts library only includes an empty constructor:

declare var Blob: {
    prototype: Blob;
    new (): Blob;
}

If this is incorrect, you could submit back the corrected version, or override it in your code. Here is a rough guess at what the original declaration should look like.

declare var Blob: {
    prototype: Blob;
    new (): Blob;
    new (request: any, mime: string): Blob;
}

I haven't specified the type for the first parameter and the names may be wrong - but as you know what Blob is up to, you can adjust these as required.

like image 194
Fenton Avatar answered Sep 27 '22 02:09

Fenton