Reputation: 63
I have a component for viewing file and one of the input variables can have both the values as string and blob
@Input() source : string | Blob;
now, how can I differentiate that source is a string or blob. I have to process if the source is Blob.
Upvotes: 2
Views: 1059
Reputation: 455
There are a couple ways:
source instanceof Blob
returns true
for Blob and false
for string.
typeof source
returns object
for Blob and string
for string.
Upvotes: 1
Reputation: 8667
Try .constructor.name
For blob created as object:
b = new Blob()
Blob {size: 0, type: ""}
b.constructor.name
"Blob"
For string creatred as object
s = new String()
String {""}
s.constructor.name
"String"
For regular string
s2 = ''
""
s2.constructor.name
"String"
Be aware that:
s2 === s
false
s2 == s
true
Upvotes: 0
Reputation: 62
TEXT and CHAR will convert to/from the character set they have associated with time. BLOB and BINARY simply store bytes.
BLOB is used for storing binary data while Text is used to store large string.
BLOB values are treated as binary strings (byte strings). They have no character set, and sorting and comparison are based on the numeric values of the bytes in column values.
TEXT values are treated as nonbinary strings (character strings). They have a character set, and values are sorted and compared based on the collation of the character set. http://dev.mysql.com/doc/refman/5.0/en/blob.html
Upvotes: 1