Saturday, January 12, 2019

What is a Blob?

I see that since Vim 8.1.765, there is a new type, the Blob. But what
is a Blob, exactly? What is it good for? I gather from the help that a
Blob is defined as any string of 0 or more hex bytes, including null
bytes if desired, and that a Blob can be created by assigning it
either a Blob literal (0z or 0Z followed by any even number of hex
digits) or the value of another Blob.

:echo displays a Blob as a List of numbers in hex, e.g. ":echo
0z00112233445566778899AABBCCDDEEFF" (without the double quotes) gives
[0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA,
0xBB, 0xCC, 0xDD, 0xEE, 0xFF] but a Blob cannot be treated as either a
List or a String: ":echo ['Mary', 'had', 'a', 'little', 'lamb'] +
0z12345678" gives E745: Using a List as a Number (sic) while "echo
'Mary had a little lamb' . 0z12345678" gives E976: Using a Blob as a
String. But ":echo 0z01234567 + 0z89ABCDEF" gives [0x01, 0x23, 0x45,
0x67, 0x89, 0xAB, 0xCD, 0xEF].

I have read somewhere in the help that blob[n] is the, er, (n-1)th
byte I think, of the Blob, but experiment shows that it is returned as
a Number, not a Blob; and that blob[i:j] returns a Blob containing all
bytes from blob[i] to blob[j] inclusive, and experiment shows that in
this case the result is indeed a Blob; but neither blob + blob nor
blob[i] with a single index are covered (yet) under :h
expression-syntax and its subtags AFAICT. So what other operations are
possible? Ah yes: Blobs can be tested for equality (i.e. :echo
0zabcdef == 0zABCDEF returns 1) and for emptyness (:echo empty(0z)
returns 1 but :echo empty(0z00) returns 0) but not for comparison
(:echo 0z123456 < 0zABCDEF returns E978: Invalid operation for Blob).
What else?


Best regards,
Tony.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: