Sunday, January 13, 2019

Fwd: What is a Blob?

On Sun, Jan 13, 2019 at 5:04 PM Bram Moolenaar <Bram@moolenaar.net> wrote:
>
>
> Tony wrote:
>
> > 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?
>
> The main reason for supporting a Blob is to deal with raw data. That
> can be an image, sound file, etc. Normally these would only be moved
> around. E.g., read it from a file and send it on a channel.
>
> In some cases it is useful to manupliate the Blob, e.g. concatenate or
> split it up. The use of this is limited. However, since a Blob mostly
> behaves as a List of bytes, Yasuhiro added several operations that are
> available for List.
>
> I have to admit that it's quite a bit of code for something that isn't
> going to be used much. But when a plugin needs to manipulate binary
> data, it's essintial.
>
> --
> hundred-and-one symptoms of being an internet addict:
> 189. You put your e-mail address in the upper left-hand corner of envelopes.

I see the general idea, but _please_ fill up (or have Yatsuhiro fill
up) the documentation, e.g. please mention all possible Blob operators
under |expr1| to |expr9|. Also mention Blobs in the description of any
functions that accept them: I found empty(), but are there others?
string2blob() or blob2list() might perhaps be interesting unless they
could be done by auto-conversion. I see test_null_blob() but what is
the difference between its output and 0z ? Or is that function to be
used only in "assert_equal(0z, test_null_blob())"? Please also flesh
up the info under |Blob|, which at the moment is not very informative
to say the least.

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: