> Bram Moolenaar schrieb am 19.10.2022 um 15:03:
> [...]
> >   
> > ! readblob({fname} [, {offset} [, {size}]])                 *readblob()*
> >             Read file {fname} in binary mode and return a |Blob|.
> > +           If {offset} is specified, read the file from the specified
> > +           offset.  If it is a negative value, it is used as an offset
> > +           from the end of the file.  E.g., to read the last 12 bytes: >
> > +                   readblob('file.bin', -12)
> > + <         If {size} is specified, only the specified size will be read.
> > +           E.g. to read the first 100 bytes of a file: >
> > +                   readblob('file.bin', 0, 100)
> > + <         If {size} is -1 or omitted, the whole data starting from
> > +           {offset} will be read.
> >             When the file can't be opened an error message is given and
> >             the result is an empty |Blob|.
> > +           When trying to read bytes beyond the end of the file the
> > +           result is an empty blob.
> >             Also see |readfile()| and |writefile()|.
> 
> I think the second to last sentence needs a clarification. What happens if
> reading starts inside the file, but the number of bytes to read would result
> in reading beyond the end of file? For example, in the given example
> 
>   readblob('file.bin', 0, 100)
> 
> what would the result be if the file is only 80 bytes large? An empty blob
> or a blob with 80 bytes? A constructed, but similar example
> 
>   readblob('file.bin', -10, 
> function_that_might_return_a_number_larger_than_10())
> 
> Does the resulting blob contain 10 bytes if the function returns a
> number larger than 10 or is the blob empty in this case?
> 
> (I would prefer readblob() to return as many bytes as possible and
> only to return an empty blob if the reading *starts* beyond the end of
> the file.  Currently I am at a computer where I cannot update to the
> newest version, so I could not test the actual behavior.)

Yeah, it is simpler if readblob() returns what it has, instead of
returning nothing if you ask for one byte too many.

For example, if you want to get the last 100 bytes of a file, and it
turns out the file is shorter, you can get the whole file.  If you
really needed 100 bytes you can easily check the length of the blob.

With the current behavior you would first have to get the size of the
file and compute the arguments yourself.

-- 
System administrators are just like women: You can't live with them and you
can't live without them.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20221021102605.4DA351C17E4%40moolenaar.net.

Reply via email to