diff runtime/doc/builtin.txt @ 30922:ed6acfafa17e v9.0.0795

patch 9.0.0795: readblob() always reads the whole file Commit: https://github.com/vim/vim/commit/11df3aeee548b959ccd4b9a4d3c44651eab6b3ce Author: K.Takata <kentkt@csc.jp> Date: Wed Oct 19 14:02:40 2022 +0100 patch 9.0.0795: readblob() always reads the whole file Problem: readblob() always reads the whole file. Solution: Add arguments to read part of the file. (Ken Takata, closes #11402)
author Bram Moolenaar <Bram@vim.org>
date Wed, 19 Oct 2022 15:15:05 +0200
parents 3295247d97a5
children 84f6f91ca02a
line wrap: on
line diff
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -445,7 +445,8 @@ pyxeval({expr})			any	evaluate |python_x
 rand([{expr}])			Number	get pseudo-random number
 range({expr} [, {max} [, {stride}]])
 				List	items from {expr} to {max}
-readblob({fname})		Blob	read a |Blob| from {fname}
+readblob({fname} [, {offset} [, {size}]])
+				Blob	read a |Blob| from {fname}
 readdir({dir} [, {expr} [, {dict}]])
 				List	file names in {dir} selected by {expr}
 readdirex({dir} [, {expr} [, {dict}]])
@@ -6847,10 +6848,21 @@ range({expr} [, {max} [, {stride}]])				
 			GetExpr()->range()
 <
 
-readblob({fname})					*readblob()*
+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()|.