patch 9.1.1016: Not possible to convert string2blob and blob2string

Problem:  Not possible to convert string2blob and blob2string
Solution: add support for the blob2str() and str2blob() functions

closes: #16373

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index a34c63a..10970bc 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -1,4 +1,4 @@
-*builtin.txt*	For Vim version 9.1.  Last change: 2025 Jan 06
+*builtin.txt*	For Vim version 9.1.  Last change: 2025 Jan 14
 
 
 		  VIM REFERENCE MANUAL	  by Bram Moolenaar
@@ -72,6 +72,7 @@
 bindtextdomain({package}, {path})
 				Bool	bind text domain to specified path
 blob2list({blob})		List	convert {blob} into a list of numbers
+blob2str({blob} [, {options}])	String	convert {blob} into a String
 browse({save}, {title}, {initdir}, {default})
 				String	put up a file requester
 browsedir({title}, {initdir})	String	put up a directory requester
@@ -609,6 +610,8 @@
 sqrt({expr})			Float	square root of {expr}
 srand([{expr}])			List	get seed for |rand()|
 state([{what}])			String	current state of Vim
+str2blob({string} [, {options}])
+				Blob	convert {string} into a Blob
 str2float({expr} [, {quoted}])	Float	convert String to Float
 str2list({expr} [, {utf8}])	List	convert each character of {expr} to
 					ASCII/UTF-8 value
@@ -1289,6 +1292,38 @@
 <
 		Return type: list<any> or list<number>
 
+
+blob2str({blob} [, {options}])				*blob2str()*
+		Return a String in the current 'encoding' by converting the
+		bytes in {blob} into characters.
+
+		If {options} is not supplied, the current 'encoding' value is
+		used to decode the bytes in {blob}.
+
+		The argument {options} is a |Dict| and supports the following
+		items:
+		    encoding	Decode the bytes in {blob} using this
+				encoding.  The value is a |String|.  See
+				|encoding-names| for the supported values.
+							*E1515*
+		An error is given and an empty string is returned if
+		an invalid byte sequence is encountered in {blob},
+
+		Returns an empty String if blob is empty.
+
+		See also |str2blob()|
+
+		Examples: >
+			blob2str(0z6162)	returns "ab"
+			blob2str(0zC2ABC2BB)	returns "«»"
+			blob2str(0zABBB, {'encoding': 'latin1'})  returns "«»"
+<
+		Can also be used as a |method|: >
+			GetBlob()->blob2str()
+<
+		Return type: |String|
+
+
 							*browse()*
 browse({save}, {title}, {initdir}, {default})
 		Put up a file requester.  This only works when "has("browse")"
@@ -10556,6 +10591,36 @@
 		Return type: |String|
 
 
+str2blob({string} [, {options}])				*str2blob()*
+		Return a Blob by converting the characters in {string} into
+		bytes.
+
+		If {options} is not supplied, the current 'encoding' value is
+		used to convert the characters in {string} into bytes.
+
+		The argument {options} is a |Dict| and supports the following
+		items:
+		    encoding	Encode the characters in {string} using this
+				encoding.  The value is a |String|.  See
+				|encoding-names| for the supported values.
+
+		An error is given and an empty blob is returned if the
+		character encoding fails.
+
+		Returns an empty Blob if {string} is empty.
+
+		See also |blob2str()|
+
+		Examples: >
+			str2blob("ab")		returns 0z6162
+			str2blob("«»")		returns 0zC2ABC2BB
+			str2blob("«»", {'encoding': 'latin1'})	returns 0zABBB
+<
+		Can also be used as a |method|: >
+			GetStr()->str2blob()
+<
+		Return type: |Blob|
+
 str2float({string} [, {quoted}])				*str2float()*
 		Convert String {string} to a Float.  This mostly works the
 		same as when using a floating point number in an expression,
diff --git a/runtime/doc/tags b/runtime/doc/tags
index 05c2126..fbc8545 100644
--- a/runtime/doc/tags
+++ b/runtime/doc/tags
@@ -4585,6 +4585,7 @@
 E1512	options.txt	/*E1512*
 E1513	message.txt	/*E1513*
 E1514	options.txt	/*E1514*
+E1515	builtin.txt	/*E1515*
 E152	helphelp.txt	/*E152*
 E153	helphelp.txt	/*E153*
 E154	helphelp.txt	/*E154*
@@ -6192,6 +6193,7 @@
 blob-literal	eval.txt	/*blob-literal*
 blob-modification	eval.txt	/*blob-modification*
 blob2list()	builtin.txt	/*blob2list()*
+blob2str()	builtin.txt	/*blob2str()*
 blockwise-examples	visual.txt	/*blockwise-examples*
 blockwise-operators	visual.txt	/*blockwise-operators*
 blockwise-put	change.txt	/*blockwise-put*
@@ -10253,6 +10255,7 @@
 statusmsg-variable	eval.txt	/*statusmsg-variable*
 stl-%!	options.txt	/*stl-%!*
 stl-%{	options.txt	/*stl-%{*
+str2blob()	builtin.txt	/*str2blob()*
 str2float()	builtin.txt	/*str2float()*
 str2list()	builtin.txt	/*str2list()*
 str2nr()	builtin.txt	/*str2nr()*
diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt
index ded30e3..cb42257 100644
--- a/runtime/doc/usr_41.txt
+++ b/runtime/doc/usr_41.txt
@@ -1,4 +1,4 @@
-*usr_41.txt*	For Vim version 9.1.  Last change: 2025 Jan 02
+*usr_41.txt*	For Vim version 9.1.  Last change: 2025 Jan 14
 
 		     VIM USER MANUAL - by Bram Moolenaar
 
@@ -801,6 +801,8 @@
 	trim()			trim characters from a string
 	bindtextdomain()	set message lookup translation base path
 	gettext()		lookup message translation
+	str2blob()		convert a string into a blob
+	blob2str()		convert a blob into a string
 
 List manipulation:					*list-functions*
 	get()			get an item without error for wrong index
diff --git a/runtime/doc/version9.txt b/runtime/doc/version9.txt
index e212230..cae2876 100644
--- a/runtime/doc/version9.txt
+++ b/runtime/doc/version9.txt
@@ -1,4 +1,4 @@
-*version9.txt*  For Vim version 9.1.  Last change: 2025 Jan 12
+*version9.txt*  For Vim version 9.1.  Last change: 2025 Jan 14
 
 
 		  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -41638,6 +41638,7 @@
 
 |base64_decode()|	decode a base64 string into a blob
 |base64_encode()|	encode a blob into a base64 string
+|blob2str()|		convert a blob into a string
 |bindtextdomain()|	set message lookup translation base path
 |diff()|		diff two Lists of strings
 |filecopy()|		copy a file {from} to {to}
@@ -41653,6 +41654,7 @@
 |matchbufline()|	all the matches of a pattern in a buffer
 |matchstrlist()|	all the matches of a pattern in a List of strings
 |popup_setbuf()|	switch to a different buffer in a popup
+|str2blob()|		convert a string into a blob
 
 
 Autocommands: ~