As typeof returns "object"..
var MyBlob = new Blob(['test text'], {type : 'text/plain'}); console.log(typeof MyBlob) // "object"
is it too early to ask for a generic solution for checking whether or not a variable is a blob as it is not yet widely supported? Or how should I go about testing for blob type in browsers which already have it implemented?
A blob has its size and MIME just like that of a simple file. The blob data is stored in the memory or filesystem of a user depending on the browser features and size of the blob. A simple blob can be used anywhere we wish just like files.
The Blob object represents a blob, which is a file-like object of immutable, raw data; they can be read as text or binary data, or converted into a ReadableStream so its methods can be used for processing the data. Blobs can represent data that isn't necessarily in a JavaScript-native format.
Interface BlobA file-like object of immutable, raw data. Blobs represent data that isn't necessarily in a JavaScript-native format. The File interface is based on Blob, inheriting blob functionality and expanding it to support files on the user's system.
A URL that was created from a JavaScript Blob can not be converted to a "normal" URL. A blob: URL does not refer to data the exists on the server, it refers to data that your browser currently has in memory, for the current page.
You can test if it is an instanceof Blob like this:
var MyBlob = new Blob(['test text'], {type : 'text/plain'}); console.log(MyBlob instanceof Blob) // true
jsFiddle: http://jsfiddle.net/jfriend00/5xkgd/
This will work for things that inherit from Blob also.
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