2

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.

IAfanasov
  • 4,775
  • 3
  • 27
  • 42

3 Answers3

1

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

  • 3
    The OP is asking in context of javascript, not mysql. You can see on tags attached to post. – Daniel Jun 17 '21 at 13:28
1

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.

Stephen Collins
  • 426
  • 5
  • 15
0

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
Daniel
  • 7,684
  • 7
  • 52
  • 76