Mercurial > hg > nginx-site
comparison xml/en/docs/njs/reference.xml @ 2604:a29676472a11
Added Buffer object info to some njs methods.
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Wed, 30 Sep 2020 22:12:05 +0100 |
parents | 5528961da54d |
children | 0ec1e1b063d7 |
comparison
equal
deleted
inserted
replaced
2603:94ebfbcd68bb | 2604:a29676472a11 |
---|---|
7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> | 7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> |
8 | 8 |
9 <article name="Reference" | 9 <article name="Reference" |
10 link="/en/docs/njs/reference.html" | 10 link="/en/docs/njs/reference.html" |
11 lang="en" | 11 lang="en" |
12 rev="54"> | 12 rev="55"> |
13 | 13 |
14 <section id="summary"> | 14 <section id="summary"> |
15 | 15 |
16 <para> | 16 <para> |
17 <link doc="index.xml">njs</link> provides objects, methods and properties | 17 <link doc="index.xml">njs</link> provides objects, methods and properties |
921 <literal>hash.update()</literal>. | 921 <literal>hash.update()</literal>. |
922 The encoding can be | 922 The encoding can be |
923 <literal>hex</literal>, | 923 <literal>hex</literal>, |
924 <literal>base64</literal>, and | 924 <literal>base64</literal>, and |
925 <literal>base64url</literal>. | 925 <literal>base64url</literal>. |
926 If encoding is not provided, a byte string is returned. | 926 If encoding is not provided, a Buffer object |
927 (<link doc="changes.xml" id="njs0.4.4">0.4.4</link>) is returned. | |
928 <note> | |
929 Before version (<link doc="changes.xml" id="njs0.4.4">0.4.4</link>), | |
930 a byte string was returned instead of a Buffer object. | |
931 </note> | |
927 </tag-desc> | 932 </tag-desc> |
928 | 933 |
929 </list> | 934 </list> |
930 </para> | 935 </para> |
931 | 936 |
958 <literal>hmac.update()</literal>. | 963 <literal>hmac.update()</literal>. |
959 The encoding can be | 964 The encoding can be |
960 <literal>hex</literal>, | 965 <literal>hex</literal>, |
961 <literal>base64</literal>, and | 966 <literal>base64</literal>, and |
962 <literal>base64url</literal>. | 967 <literal>base64url</literal>. |
963 If encoding is not provided, a byte string is returned. | 968 If encoding is not provided, a Buffer object |
969 (<link doc="changes.xml" id="njs0.4.4">0.4.4</link>) is returned. | |
970 <note> | |
971 Before version <link doc="changes.xml" id="njs0.4.4">0.4.4</link>, | |
972 a byte string was returned instead of a Buffer object. | |
973 </note> | |
964 </tag-desc> | 974 </tag-desc> |
965 </list> | 975 </list> |
966 </para> | 976 </para> |
967 | 977 |
968 <para> | 978 <para> |
1030 <tag-name id="fs_appendfilesync"><literal>appendFileSync(<value>filename</value>, | 1040 <tag-name id="fs_appendfilesync"><literal>appendFileSync(<value>filename</value>, |
1031 <value>data</value>[, <value>options</value>])</literal></tag-name> | 1041 <value>data</value>[, <value>options</value>])</literal></tag-name> |
1032 <tag-desc> | 1042 <tag-desc> |
1033 Synchronously appends specified <literal>data</literal> | 1043 Synchronously appends specified <literal>data</literal> |
1034 to a file with provided <literal>filename</literal>. | 1044 to a file with provided <literal>filename</literal>. |
1045 The <literal>data</literal> is expected to be a string | |
1046 or a Buffer object (<link doc="changes.xml" id="njs0.4.4">0.4.4</link>). | |
1035 If the file does not exist, it will be created. | 1047 If the file does not exist, it will be created. |
1036 The <literal>options</literal> parameter is expected to be | 1048 The <literal>options</literal> parameter is expected to be |
1037 an object with the following keys: | 1049 an object with the following keys: |
1038 <list type="tag"> | 1050 <list type="tag"> |
1039 | 1051 |
1081 or an object with the following keys: | 1093 or an object with the following keys: |
1082 <list type="tag"> | 1094 <list type="tag"> |
1083 | 1095 |
1084 <tag-name id="fs_readdirsync_encoding"><literal>encoding</literal></tag-name> | 1096 <tag-name id="fs_readdirsync_encoding"><literal>encoding</literal></tag-name> |
1085 <tag-desc> | 1097 <tag-desc> |
1086 encoding, by default is not specified. | 1098 encoding, by default is <literal>utf8</literal>. |
1087 The encoding can be <literal>utf8</literal>. | 1099 The encoding can be <literal>utf8</literal> and <literal>buffer</literal> |
1100 (<link doc="changes.xml" id="njs0.4.4">0.4.4</link>). | |
1088 </tag-desc> | 1101 </tag-desc> |
1089 | 1102 |
1090 <tag-name id="fs_readdirsync_withfiletypes"><literal>withFileTypes</literal></tag-name> | 1103 <tag-name id="fs_readdirsync_withfiletypes"><literal>withFileTypes</literal></tag-name> |
1091 <tag-desc> | 1104 <tag-desc> |
1092 if set to <literal>true</literal>, the files array will contain | 1105 if set to <literal>true</literal>, the files array will contain |
1102 <tag-desc> | 1115 <tag-desc> |
1103 Synchronously returns the contents of the file | 1116 Synchronously returns the contents of the file |
1104 with provided <literal>filename</literal>. | 1117 with provided <literal>filename</literal>. |
1105 The <literal>options</literal> parameter holds | 1118 The <literal>options</literal> parameter holds |
1106 <literal>string</literal> that specifies encoding. | 1119 <literal>string</literal> that specifies encoding. |
1107 If not specified, a <link id="string_tobytes">byte string</link> is returned. | 1120 If an encoding is specified, a string is returned, |
1108 If <literal>utf8</literal> encoding is specified, a Unicode string is returned. | 1121 otherwise, a Buffer object |
1122 (<link doc="changes.xml" id="njs0.4.4">0.4.4</link>) is returned. | |
1123 <note> | |
1124 Before version <link doc="changes.xml" id="njs0.4.4">0.4.4</link>, | |
1125 a <link id="string_tobytes">byte string</link> was returned | |
1126 if encoding was not specified. | |
1127 </note> | |
1109 Otherwise, <literal>options</literal> is expected to be | 1128 Otherwise, <literal>options</literal> is expected to be |
1110 an object with the following keys: | 1129 an object with the following keys: |
1111 <list type="tag"> | 1130 <list type="tag"> |
1112 | 1131 |
1113 <tag-name><literal>encoding</literal></tag-name> | 1132 <tag-name><literal>encoding</literal></tag-name> |
1114 <tag-desc> | 1133 <tag-desc> |
1115 encoding, by default is not specified. | 1134 encoding, by default is not specified. |
1116 The encoding can be <literal>utf8</literal> | 1135 The encoding can be <literal>utf8</literal>, |
1136 <literal>hex</literal> | |
1137 (<link doc="changes.xml" id="njs0.4.4">0.4.4</link>), | |
1138 <literal>base64</literal> | |
1139 (<link doc="changes.xml" id="njs0.4.4">0.4.4</link>), | |
1140 <literal>base64url</literal> | |
1141 (<link doc="changes.xml" id="njs0.4.4">0.4.4</link>). | |
1117 </tag-desc> | 1142 </tag-desc> |
1118 | 1143 |
1119 <tag-name><literal>flag</literal></tag-name> | 1144 <tag-name><literal>flag</literal></tag-name> |
1120 <tag-desc> | 1145 <tag-desc> |
1121 file system <link id="njs_api_fs_flags">flag</link>, | 1146 file system <link id="njs_api_fs_flags">flag</link>, |
1126 <example> | 1151 <example> |
1127 >> var fs = require('fs') | 1152 >> var fs = require('fs') |
1128 undefined | 1153 undefined |
1129 >> var file = fs.readFileSync('/file/path.tar.gz') | 1154 >> var file = fs.readFileSync('/file/path.tar.gz') |
1130 undefined | 1155 undefined |
1131 >> var gzipped = /^\x1f\x8b/.test(file); gzipped | 1156 >> var gzipped = file.slice(0,2).toString('hex') === '1f8b'; gzipped |
1132 true | 1157 true |
1133 </example> | 1158 </example> |
1134 </tag-desc> | 1159 </tag-desc> |
1135 | 1160 |
1136 <tag-name id="fs_realpathsync"><literal>realpathSync(<value>path</value>[, | 1161 <tag-name id="fs_realpathsync"><literal>realpathSync(<value>path</value>[, |
1185 <value>data</value>[, | 1210 <value>data</value>[, |
1186 <value>options</value>])</literal></tag-name> | 1211 <value>options</value>])</literal></tag-name> |
1187 <tag-desc> | 1212 <tag-desc> |
1188 Synchronously writes <literal>data</literal> to a file | 1213 Synchronously writes <literal>data</literal> to a file |
1189 with provided <literal>filename</literal>. | 1214 with provided <literal>filename</literal>. |
1215 The <literal>data</literal> is expected to be a string | |
1216 or a Buffer object (<link doc="changes.xml" id="njs0.4.4">0.4.4</link>). | |
1190 If the file does not exist, it will be created, | 1217 If the file does not exist, it will be created, |
1191 if the file exists, it will be replaced. | 1218 if the file exists, it will be replaced. |
1192 The <literal>options</literal> parameter is expected to be | 1219 The <literal>options</literal> parameter is expected to be |
1193 an object with the following keys: | 1220 an object with the following keys: |
1194 <list type="tag"> | 1221 <list type="tag"> |