comparison xml/en/docs/njs/reference.xml @ 3020:61996cb486f9

Reordered and added to toc fs methods in njs Reference.
author Yaroslav Zhuravlev <yar@nginx.com>
date Mon, 23 Oct 2023 19:23:28 +0100
parents 3a85326ed38c
children ec6f7fcd3d90
comparison
equal deleted inserted replaced
3019:7f8bedbdbe4f 3020:61996cb486f9
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="118"> 12 rev="119">
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
4865 <tr><td><link id="fs_fstatsync"><literal>fs.fstatSync()</literal></link></td></tr> 4865 <tr><td><link id="fs_fstatsync"><literal>fs.fstatSync()</literal></link></td></tr>
4866 <tr><td><link id="fs_lstatsync"><literal>fs.lstatSync()</literal></link></td></tr> 4866 <tr><td><link id="fs_lstatsync"><literal>fs.lstatSync()</literal></link></td></tr>
4867 <tr><td><link id="fs_mkdirsync"><literal>fs.mkdirSync()</literal></link></td></tr> 4867 <tr><td><link id="fs_mkdirsync"><literal>fs.mkdirSync()</literal></link></td></tr>
4868 <tr><td><link id="fs_opensync"><literal>fs.openSync()</literal></link></td></tr> 4868 <tr><td><link id="fs_opensync"><literal>fs.openSync()</literal></link></td></tr>
4869 <tr><td><link id="fs_promises_open"><literal>fs.promises.open()</literal></link></td></tr> 4869 <tr><td><link id="fs_promises_open"><literal>fs.promises.open()</literal></link></td></tr>
4870 <tr><td><link id="fs_readsync"><literal>fs.readSync()</literal></link></td></tr>
4871 <tr><td><link id="fs_readdirsync"><literal>fs.readdirSync()</literal></link></td></tr> 4870 <tr><td><link id="fs_readdirsync"><literal>fs.readdirSync()</literal></link></td></tr>
4872 <tr><td><link id="fs_readfilesync"><literal>fs.readFileSync()</literal></link></td></tr> 4871 <tr><td><link id="fs_readfilesync"><literal>fs.readFileSync()</literal></link></td></tr>
4872 <tr><td><link id="fs_readsync"><literal>fs.readSync()</literal></link></td></tr>
4873 <tr><td><link id="fs_realpathsync"><literal>fs.realpathSync()</literal></link></td></tr> 4873 <tr><td><link id="fs_realpathsync"><literal>fs.realpathSync()</literal></link></td></tr>
4874 <tr><td><link id="fs_renamesync"><literal>fs.renameSync()</literal></link></td></tr> 4874 <tr><td><link id="fs_renamesync"><literal>fs.renameSync()</literal></link></td></tr>
4875 <tr><td><link id="fs_rmdirsync"><literal>fs.rmdirSync()</literal></link></td></tr> 4875 <tr><td><link id="fs_rmdirsync"><literal>fs.rmdirSync()</literal></link></td></tr>
4876 <tr><td><link id="fs_statsync"><literal>fs.statSync()</literal></link></td></tr> 4876 <tr><td><link id="fs_statsync"><literal>fs.statSync()</literal></link></td></tr>
4877 <tr><td><link id="fs_symlinksync"><literal>fs.symlinkSync()</literal></link></td></tr> 4877 <tr><td><link id="fs_symlinksync"><literal>fs.symlinkSync()</literal></link></td></tr>
4878 <tr><td><link id="fs_unlinksync"><literal>fs.unlinkSync()</literal></link></td></tr>
4879 <tr><td><link id="fs_writefilesync"><literal>fs.writeFileSync()</literal></link></td></tr>
4878 <tr><td><link id="fs_writesync_buf"><literal>fs.writeSync()</literal></link></td></tr> 4880 <tr><td><link id="fs_writesync_buf"><literal>fs.writeSync()</literal></link></td></tr>
4879 <tr><td><link id="fs_writesync_str"><literal>fs.writeSync()</literal></link></td></tr> 4881 <tr><td><link id="fs_writesync_str"><literal>fs.writeSync()</literal></link></td></tr>
4880 <tr><td><link id="fs_unlinksync"><literal>fs.unlinkSync()</literal></link></td></tr> 4882 </table>
4881 <tr><td><link id="fs_writefilesync"><literal>fs.writeFileSync()</literal></link></td></tr> 4883 </para>
4884
4885 <para>
4886 <table width="100%">
4887 <tr><td><link id="fs_dirent"><literal>fs.Dirent</literal></link></td></tr>
4888 <tr><td><link id="fs_filehandle"><literal>fs.FileHandle</literal></link></td></tr>
4889 <tr><td><link id="fs_stats"><literal>fs.Stats</literal></link></td></tr>
4890 <tr><td><link id="access_const"><literal>File Access Constants</literal></link></td></tr>
4891 <tr><td><link id="njs_api_fs_flags"><literal>File System Flags</literal></link></td></tr>
4882 </table> 4892 </table>
4883 </para> 4893 </para>
4884 4894
4885 <para> 4895 <para>
4886 The File System module provides operations with files. 4896 The File System module provides operations with files.
5041 <tag-desc> 5051 <tag-desc>
5042 mode option, by default is <literal>0o666</literal> 5052 mode option, by default is <literal>0o666</literal>
5043 </tag-desc> 5053 </tag-desc>
5044 5054
5045 </list> 5055 </list>
5046 </tag-desc>
5047
5048 <tag-name id="fs_readsync"><literal>readSync(<value>fd</value>,
5049 <value>buffer</value>, <value>offset</value>[,
5050 <value>length</value>[, <value>position</value>]])</literal></tag-name>
5051 <tag-desc>
5052 Reads the content of a file path using file descriptor <literal>fd</literal>,
5053 returns the number of bytes read
5054 (<link doc="changes.xml" id="njs0.7.7">0.7.7</link>).
5055
5056 <list type="tag">
5057
5058 <tag-name><literal>buffer</literal></tag-name>
5059 <tag-desc>
5060 the <literal>buffer</literal> value can be a
5061 <literal>Buffer</literal>,
5062 <literal>TypedArray</literal>, or
5063 <literal>DataView</literal>
5064 </tag-desc>
5065
5066 <tag-name><literal>offset</literal></tag-name>
5067 <tag-desc>
5068 is an <literal>integer</literal> representing
5069 the position in buffer to write the data to
5070 </tag-desc>
5071
5072 <tag-name><literal>length</literal></tag-name>
5073 <tag-desc>
5074 is an <literal>integer</literal> representing
5075 the number of bytes to read
5076 </tag-desc>
5077
5078 <tag-name><literal>position</literal></tag-name>
5079 <tag-desc>
5080 specifies where to begin reading from in the file,
5081 the value can be
5082 <literal>integer</literal> or
5083 <literal>null</literal>,
5084 by default is <literal>null</literal>.
5085 If <literal>position</literal> is <literal>null</literal>,
5086 data will be read from the current file position,
5087 and the file position will be updated.
5088 If position is an <literal>integer</literal>,
5089 the file position will be unchanged
5090 </tag-desc>
5091 </list>
5092
5093 </tag-desc> 5056 </tag-desc>
5094 5057
5095 <tag-name id="fs_readdirsync"><literal>readdirSync(<value>path</value>[, 5058 <tag-name id="fs_readdirsync"><literal>readdirSync(<value>path</value>[,
5096 <value>options</value>])</literal></tag-name> 5059 <value>options</value>])</literal></tag-name>
5097 <tag-desc> 5060 <tag-desc>
5166 >> var gzipped = file.slice(0,2).toString('hex') === '1f8b'; gzipped 5129 >> var gzipped = file.slice(0,2).toString('hex') === '1f8b'; gzipped
5167 true 5130 true
5168 </example> 5131 </example>
5169 </tag-desc> 5132 </tag-desc>
5170 5133
5134 <tag-name id="fs_readsync"><literal>readSync(<value>fd</value>,
5135 <value>buffer</value>, <value>offset</value>[,
5136 <value>length</value>[, <value>position</value>]])</literal></tag-name>
5137 <tag-desc>
5138 Reads the content of a file path using file descriptor <literal>fd</literal>,
5139 returns the number of bytes read
5140 (<link doc="changes.xml" id="njs0.7.7">0.7.7</link>).
5141
5142 <list type="tag">
5143
5144 <tag-name><literal>buffer</literal></tag-name>
5145 <tag-desc>
5146 the <literal>buffer</literal> value can be a
5147 <literal>Buffer</literal>,
5148 <literal>TypedArray</literal>, or
5149 <literal>DataView</literal>
5150 </tag-desc>
5151
5152 <tag-name><literal>offset</literal></tag-name>
5153 <tag-desc>
5154 is an <literal>integer</literal> representing
5155 the position in buffer to write the data to
5156 </tag-desc>
5157
5158 <tag-name><literal>length</literal></tag-name>
5159 <tag-desc>
5160 is an <literal>integer</literal> representing
5161 the number of bytes to read
5162 </tag-desc>
5163
5164 <tag-name><literal>position</literal></tag-name>
5165 <tag-desc>
5166 specifies where to begin reading from in the file,
5167 the value can be
5168 <literal>integer</literal> or
5169 <literal>null</literal>,
5170 by default is <literal>null</literal>.
5171 If <literal>position</literal> is <literal>null</literal>,
5172 data will be read from the current file position,
5173 and the file position will be updated.
5174 If position is an <literal>integer</literal>,
5175 the file position will be unchanged
5176 </tag-desc>
5177 </list>
5178
5179 </tag-desc>
5180
5171 <tag-name id="fs_realpathsync"><literal>realpathSync(<value>path</value>[, 5181 <tag-name id="fs_realpathsync"><literal>realpathSync(<value>path</value>[,
5172 <value>options</value>])</literal></tag-name> 5182 <value>options</value>])</literal></tag-name>
5173 <tag-desc> 5183 <tag-desc>
5174 Synchronously computes the canonical pathname by resolving 5184 Synchronously computes the canonical pathname by resolving
5175 <literal>.</literal>, <literal>..</literal> and symbolic links using 5185 <literal>.</literal>, <literal>..</literal> and symbolic links using
5231 <link url="http://man7.org/linux/man-pages/man2/symlink.2.html">symlink(2)</link> 5241 <link url="http://man7.org/linux/man-pages/man2/symlink.2.html">symlink(2)</link>
5232 (<link doc="changes.xml" id="njs0.3.9">0.3.9</link>). 5242 (<link doc="changes.xml" id="njs0.3.9">0.3.9</link>).
5233 Relative targets are relative to the link’s parent directory. 5243 Relative targets are relative to the link’s parent directory.
5234 </tag-desc> 5244 </tag-desc>
5235 5245
5246 <tag-name id="fs_unlinksync"><literal>unlinkSync(<value>path</value>)</literal></tag-name>
5247 <tag-desc>
5248 Synchronously unlinks a file by <literal>path</literal>
5249 (<link doc="changes.xml" id="njs0.3.9">0.3.9</link>).
5250 </tag-desc>
5251
5252 <tag-name id="fs_writefilesync"><literal>writeFileSync(<value>filename</value>,
5253 <value>data</value>[,
5254 <value>options</value>])</literal></tag-name>
5255 <tag-desc>
5256 Synchronously writes <literal>data</literal> to a file
5257 with provided <literal>filename</literal>.
5258 The <literal>data</literal> is expected to be a string
5259 or a Buffer object (<link doc="changes.xml" id="njs0.4.4">0.4.4</link>).
5260 If the file does not exist, it will be created,
5261 if the file exists, it will be replaced.
5262 The <literal>options</literal> parameter is expected to be
5263 an object with the following keys:
5264 <list type="tag">
5265 <tag-name><literal>mode</literal></tag-name>
5266 <tag-desc>
5267 mode option, by default is <literal>0o666</literal>
5268 </tag-desc>
5269
5270 <tag-name><literal>flag</literal></tag-name>
5271 <tag-desc>
5272 file system <link id="njs_api_fs_flags">flag</link>,
5273 by default is <literal>w</literal>
5274 </tag-desc>
5275
5276 </list>
5277 <example>
5278 >> var fs = require('fs')
5279 undefined
5280 >> var file = fs.writeFileSync('hello.txt', 'Hello world')
5281 undefined
5282 </example>
5283 </tag-desc>
5284
5236 <tag-name id="fs_writesync_buf"><literal>writeSync(<value>fd</value>, 5285 <tag-name id="fs_writesync_buf"><literal>writeSync(<value>fd</value>,
5237 <value>buffer</value>, <value>offset</value>[, 5286 <value>buffer</value>, <value>offset</value>[,
5238 <value>length</value>[, <value>position</value>]])</literal></tag-name> 5287 <value>length</value>[, <value>position</value>]])</literal></tag-name>
5239 <tag-desc> 5288 <tag-desc>
5240 Writes a buffer to a file using file descriptor, 5289 Writes a buffer to a file using file descriptor,
5318 is a <literal>string</literal>, 5367 is a <literal>string</literal>,
5319 by default is <literal>utf8</literal> 5368 by default is <literal>utf8</literal>
5320 </tag-desc> 5369 </tag-desc>
5321 </list> 5370 </list>
5322 5371
5323 </tag-desc>
5324
5325 <tag-name id="fs_unlinksync"><literal>unlinkSync(<value>path</value>)</literal></tag-name>
5326 <tag-desc>
5327 Synchronously unlinks a file by <literal>path</literal>
5328 (<link doc="changes.xml" id="njs0.3.9">0.3.9</link>).
5329 </tag-desc>
5330
5331 <tag-name id="fs_writefilesync"><literal>writeFileSync(<value>filename</value>,
5332 <value>data</value>[,
5333 <value>options</value>])</literal></tag-name>
5334 <tag-desc>
5335 Synchronously writes <literal>data</literal> to a file
5336 with provided <literal>filename</literal>.
5337 The <literal>data</literal> is expected to be a string
5338 or a Buffer object (<link doc="changes.xml" id="njs0.4.4">0.4.4</link>).
5339 If the file does not exist, it will be created,
5340 if the file exists, it will be replaced.
5341 The <literal>options</literal> parameter is expected to be
5342 an object with the following keys:
5343 <list type="tag">
5344 <tag-name><literal>mode</literal></tag-name>
5345 <tag-desc>
5346 mode option, by default is <literal>0o666</literal>
5347 </tag-desc>
5348
5349 <tag-name><literal>flag</literal></tag-name>
5350 <tag-desc>
5351 file system <link id="njs_api_fs_flags">flag</link>,
5352 by default is <literal>w</literal>
5353 </tag-desc>
5354
5355 </list>
5356 <example>
5357 >> var fs = require('fs')
5358 undefined
5359 >> var file = fs.writeFileSync('hello.txt', 'Hello world')
5360 undefined
5361 </example>
5362 </tag-desc> 5372 </tag-desc>
5363 5373
5364 </list> 5374 </list>
5365 </para> 5375 </para>
5366 5376