~yolanda.robla/ubuntu/trusty/nodejs/add_distribution

« back to all changes in this revision

Viewing changes to doc/api/api/fs.html

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2013-08-14 00:16:46 UTC
  • mfrom: (7.1.40 sid)
  • Revision ID: package-import@ubuntu.com-20130814001646-bzlysfh8sd6mukbo
Tags: 0.10.15~dfsg1-4
* Update 2005 patch, adding a handful of tests that can fail on
  slow platforms.
* Add 1004 patch to fix test failures when writing NaN to buffer
  on mipsel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!doctype html>
2
 
<html lang="en">
3
 
<head>
4
 
  <meta charset="utf-8">
5
 
  <title>File System Node.js v0.6.18 Manual &amp; Documentation</title>
6
 
  <link rel="stylesheet" href="assets/style.css">
7
 
  <link rel="stylesheet" href="assets/sh.css">
8
 
  <link rel="canonical" href="http://nodejs.org/api/fs.html">
9
 
</head>
10
 
<body class="alt apidoc" id="api-section-fs">
11
 
    <div id="intro" class="interior">
12
 
        <a href="/" title="Go back to the home page">
13
 
            <img id="logo" src="http://nodejs.org/images/logo-light.png" alt="node.js">
14
 
        </a>
15
 
    </div>
16
 
    <div id="content" class="clearfix">
17
 
        <div id="column2" class="interior">
18
 
            <ul>
19
 
                <li><a href="/" class="home">Home</a></li>
20
 
                <li><a href="/#download" class="download">Download</a></li>
21
 
                <li><a href="/about/" class="about">About</a></li>
22
 
                <li><a href="http://search.npmjs.org/" class="npm">npm Registry</a></li>
23
 
                <li><a href="http://nodejs.org/api/" class="docs current">Docs</a></li>
24
 
                <li><a href="http://blog.nodejs.org" class="blog">Blog</a></li>
25
 
                <li><a href="/community/" class="community">Community</a></li>
26
 
                <li><a href="/logos/" class="logos">Logos</a></li>
27
 
                <li><a href="http://jobs.nodejs.org/" class="jobs">Jobs</a></li>
28
 
            </ul>
29
 
            <p class="twitter"><a href="http://twitter.com/nodejs">@nodejs</a></p>
30
 
        </div>
31
 
 
32
 
        <div id="column1" class="interior">
33
 
          <header>
34
 
            <h1>Node.js v0.6.18 Manual &amp; Documentation</h1>
35
 
            <div id="gtoc">
36
 
              <p>
37
 
                <a href="index.html" name="toc">Index</a> |
38
 
                <a href="all.html">View on single page</a> |
39
 
                <a href="fs.json">View as JSON</a>
40
 
              </p>
41
 
            </div>
42
 
            <hr>
43
 
          </header>
44
 
 
45
 
          <div id="toc">
46
 
            <h2>Table of Contents</h2>
47
 
            <ul>
48
 
<li><a href="#fs_file_system">File System</a><ul>
49
 
<li><a href="#fs_fs_rename_path1_path2_callback">fs.rename(path1, path2, [callback])</a></li>
50
 
<li><a href="#fs_fs_renamesync_path1_path2">fs.renameSync(path1, path2)</a></li>
51
 
<li><a href="#fs_fs_truncate_fd_len_callback">fs.truncate(fd, len, [callback])</a></li>
52
 
<li><a href="#fs_fs_truncatesync_fd_len">fs.truncateSync(fd, len)</a></li>
53
 
<li><a href="#fs_fs_chown_path_uid_gid_callback">fs.chown(path, uid, gid, [callback])</a></li>
54
 
<li><a href="#fs_fs_chownsync_path_uid_gid">fs.chownSync(path, uid, gid)</a></li>
55
 
<li><a href="#fs_fs_fchown_fd_uid_gid_callback">fs.fchown(fd, uid, gid, [callback])</a></li>
56
 
<li><a href="#fs_fs_fchownsync_fd_uid_gid">fs.fchownSync(fd, uid, gid)</a></li>
57
 
<li><a href="#fs_fs_lchown_path_uid_gid_callback">fs.lchown(path, uid, gid, [callback])</a></li>
58
 
<li><a href="#fs_fs_lchownsync_path_uid_gid">fs.lchownSync(path, uid, gid)</a></li>
59
 
<li><a href="#fs_fs_chmod_path_mode_callback">fs.chmod(path, mode, [callback])</a></li>
60
 
<li><a href="#fs_fs_chmodsync_path_mode">fs.chmodSync(path, mode)</a></li>
61
 
<li><a href="#fs_fs_fchmod_fd_mode_callback">fs.fchmod(fd, mode, [callback])</a></li>
62
 
<li><a href="#fs_fs_fchmodsync_fd_mode">fs.fchmodSync(fd, mode)</a></li>
63
 
<li><a href="#fs_fs_lchmod_path_mode_callback">fs.lchmod(path, mode, [callback])</a></li>
64
 
<li><a href="#fs_fs_lchmodsync_path_mode">fs.lchmodSync(path, mode)</a></li>
65
 
<li><a href="#fs_fs_stat_path_callback">fs.stat(path, [callback])</a></li>
66
 
<li><a href="#fs_fs_lstat_path_callback">fs.lstat(path, [callback])</a></li>
67
 
<li><a href="#fs_fs_fstat_fd_callback">fs.fstat(fd, [callback])</a></li>
68
 
<li><a href="#fs_fs_statsync_path">fs.statSync(path)</a></li>
69
 
<li><a href="#fs_fs_lstatsync_path">fs.lstatSync(path)</a></li>
70
 
<li><a href="#fs_fs_fstatsync_fd">fs.fstatSync(fd)</a></li>
71
 
<li><a href="#fs_fs_link_srcpath_dstpath_callback">fs.link(srcpath, dstpath, [callback])</a></li>
72
 
<li><a href="#fs_fs_linksync_srcpath_dstpath">fs.linkSync(srcpath, dstpath)</a></li>
73
 
<li><a href="#fs_fs_symlink_linkdata_path_type_callback">fs.symlink(linkdata, path, [type], [callback])</a></li>
74
 
<li><a href="#fs_fs_symlinksync_linkdata_path_type">fs.symlinkSync(linkdata, path, [type])</a></li>
75
 
<li><a href="#fs_fs_readlink_path_callback">fs.readlink(path, [callback])</a></li>
76
 
<li><a href="#fs_fs_readlinksync_path">fs.readlinkSync(path)</a></li>
77
 
<li><a href="#fs_fs_realpath_path_callback">fs.realpath(path, [callback])</a></li>
78
 
<li><a href="#fs_fs_realpathsync_path">fs.realpathSync(path)</a></li>
79
 
<li><a href="#fs_fs_unlink_path_callback">fs.unlink(path, [callback])</a></li>
80
 
<li><a href="#fs_fs_unlinksync_path">fs.unlinkSync(path)</a></li>
81
 
<li><a href="#fs_fs_rmdir_path_callback">fs.rmdir(path, [callback])</a></li>
82
 
<li><a href="#fs_fs_rmdirsync_path">fs.rmdirSync(path)</a></li>
83
 
<li><a href="#fs_fs_mkdir_path_mode_callback">fs.mkdir(path, [mode], [callback])</a></li>
84
 
<li><a href="#fs_fs_mkdirsync_path_mode">fs.mkdirSync(path, [mode])</a></li>
85
 
<li><a href="#fs_fs_readdir_path_callback">fs.readdir(path, [callback])</a></li>
86
 
<li><a href="#fs_fs_readdirsync_path">fs.readdirSync(path)</a></li>
87
 
<li><a href="#fs_fs_close_fd_callback">fs.close(fd, [callback])</a></li>
88
 
<li><a href="#fs_fs_closesync_fd">fs.closeSync(fd)</a></li>
89
 
<li><a href="#fs_fs_open_path_flags_mode_callback">fs.open(path, flags, [mode], [callback])</a></li>
90
 
<li><a href="#fs_fs_opensync_path_flags_mode">fs.openSync(path, flags, [mode])</a></li>
91
 
<li><a href="#fs_fs_utimes_path_atime_mtime_callback">fs.utimes(path, atime, mtime, [callback])</a></li>
92
 
<li><a href="#fs_fs_utimessync_path_atime_mtime">fs.utimesSync(path, atime, mtime)</a></li>
93
 
<li><a href="#fs_fs_futimes_fd_atime_mtime_callback">fs.futimes(fd, atime, mtime, [callback])</a></li>
94
 
<li><a href="#fs_fs_futimessync_fd_atime_mtime">fs.futimesSync(fd, atime, mtime)</a></li>
95
 
<li><a href="#fs_fs_fsync_fd_callback">fs.fsync(fd, [callback])</a></li>
96
 
<li><a href="#fs_fs_fsyncsync_fd">fs.fsyncSync(fd)</a></li>
97
 
<li><a href="#fs_fs_write_fd_buffer_offset_length_position_callback">fs.write(fd, buffer, offset, length, position, [callback])</a></li>
98
 
<li><a href="#fs_fs_writesync_fd_buffer_offset_length_position">fs.writeSync(fd, buffer, offset, length, position)</a></li>
99
 
<li><a href="#fs_fs_writesync_fd_str_position_encoding">fs.writeSync(fd, str, position, [encoding])</a></li>
100
 
<li><a href="#fs_fs_read_fd_buffer_offset_length_position_callback">fs.read(fd, buffer, offset, length, position, [callback])</a></li>
101
 
<li><a href="#fs_fs_readsync_fd_buffer_offset_length_position">fs.readSync(fd, buffer, offset, length, position)</a></li>
102
 
<li><a href="#fs_fs_readsync_fd_length_position_encoding">fs.readSync(fd, length, position, encoding)</a></li>
103
 
<li><a href="#fs_fs_readfile_filename_encoding_callback">fs.readFile(filename, [encoding], [callback])</a></li>
104
 
<li><a href="#fs_fs_readfilesync_filename_encoding">fs.readFileSync(filename, [encoding])</a></li>
105
 
<li><a href="#fs_fs_writefile_filename_data_encoding_callback">fs.writeFile(filename, data, [encoding], [callback])</a></li>
106
 
<li><a href="#fs_fs_writefilesync_filename_data_encoding">fs.writeFileSync(filename, data, [encoding])</a></li>
107
 
<li><a href="#fs_fs_watchfile_filename_options_listener">fs.watchFile(filename, [options], listener)</a></li>
108
 
<li><a href="#fs_fs_unwatchfile_filename">fs.unwatchFile(filename)</a></li>
109
 
<li><a href="#fs_fs_watch_filename_options_listener">fs.watch(filename, [options], listener)</a><ul>
110
 
<li><a href="#fs_caveats">Caveats</a><ul>
111
 
<li><a href="#fs_availability">Availability</a></li>
112
 
<li><a href="#fs_filename_argument">Filename Argument</a></li>
113
 
</ul>
114
 
</li>
115
 
</ul>
116
 
</li>
117
 
<li><a href="#fs_class_fs_stats">Class: fs.Stats</a></li>
118
 
<li><a href="#fs_fs_createreadstream_path_options">fs.createReadStream(path, [options])</a></li>
119
 
<li><a href="#fs_class_fs_readstream">Class: fs.ReadStream</a><ul>
120
 
<li><a href="#fs_event_open">Event: &apos;open&apos;</a></li>
121
 
</ul>
122
 
</li>
123
 
<li><a href="#fs_fs_createwritestream_path_options">fs.createWriteStream(path, [options])</a></li>
124
 
<li><a href="#fs_fs_writestream">fs.WriteStream</a><ul>
125
 
<li><a href="#fs_event_open_1">Event: &apos;open&apos;</a></li>
126
 
<li><a href="#fs_file_byteswritten">file.bytesWritten</a></li>
127
 
</ul>
128
 
</li>
129
 
<li><a href="#fs_class_fs_fswatcher">Class: fs.FSWatcher</a><ul>
130
 
<li><a href="#fs_watcher_close">watcher.close()</a></li>
131
 
<li><a href="#fs_event_change">Event: &apos;change&apos;</a></li>
132
 
<li><a href="#fs_event_error">Event: &apos;error&apos;</a></li>
133
 
</ul>
134
 
</li>
135
 
</ul>
136
 
</li>
137
 
</ul>
138
 
 
139
 
          </div>
140
 
 
141
 
          <div id="apicontent">
142
 
            <h1>File System<span><a class="mark" href="#fs_file_system" id="fs_file_system">#</a></span></h1>
143
 
<pre><code>Stability: 3 - Stable</code></pre>
144
 
<!--name=fs-->
145
 
 
146
 
<p>File I/O is provided by simple wrappers around standard POSIX functions.  To
147
 
use this module do <code>require(&apos;fs&apos;)</code>. All the methods have asynchronous and
148
 
synchronous forms.
149
 
 
150
 
</p>
151
 
<p>The asynchronous form always take a completion callback as its last argument.
152
 
The arguments passed to the completion callback depend on the method, but the
153
 
first argument is always reserved for an exception. If the operation was
154
 
completed successfully, then the first argument will be <code>null</code> or <code>undefined</code>.
155
 
 
156
 
</p>
157
 
<p>When using the synchronous form any exceptions are immediately thrown.
158
 
You can use try/catch to handle exceptions or allow them to bubble up.
159
 
 
160
 
</p>
161
 
<p>Here is an example of the asynchronous version:
162
 
 
163
 
</p>
164
 
<pre><code>var fs = require(&apos;fs&apos;);
165
 
 
166
 
fs.unlink(&apos;/tmp/hello&apos;, function (err) {
167
 
  if (err) throw err;
168
 
  console.log(&apos;successfully deleted /tmp/hello&apos;);
169
 
});</code></pre>
170
 
<p>Here is the synchronous version:
171
 
 
172
 
</p>
173
 
<pre><code>var fs = require(&apos;fs&apos;);
174
 
 
175
 
fs.unlinkSync(&apos;/tmp/hello&apos;)
176
 
console.log(&apos;successfully deleted /tmp/hello&apos;);</code></pre>
177
 
<p>With the asynchronous methods there is no guaranteed ordering. So the
178
 
following is prone to error:
179
 
 
180
 
</p>
181
 
<pre><code>fs.rename(&apos;/tmp/hello&apos;, &apos;/tmp/world&apos;, function (err) {
182
 
  if (err) throw err;
183
 
  console.log(&apos;renamed complete&apos;);
184
 
});
185
 
fs.stat(&apos;/tmp/world&apos;, function (err, stats) {
186
 
  if (err) throw err;
187
 
  console.log(&apos;stats: &apos; + JSON.stringify(stats));
188
 
});</code></pre>
189
 
<p>It could be that <code>fs.stat</code> is executed before <code>fs.rename</code>.
190
 
The correct way to do this is to chain the callbacks.
191
 
 
192
 
</p>
193
 
<pre><code>fs.rename(&apos;/tmp/hello&apos;, &apos;/tmp/world&apos;, function (err) {
194
 
  if (err) throw err;
195
 
  fs.stat(&apos;/tmp/world&apos;, function (err, stats) {
196
 
    if (err) throw err;
197
 
    console.log(&apos;stats: &apos; + JSON.stringify(stats));
198
 
  });
199
 
});</code></pre>
200
 
<p>In busy processes, the programmer is <em>strongly encouraged</em> to use the
201
 
asynchronous versions of these calls. The synchronous versions will block
202
 
the entire process until they complete--halting all connections.
203
 
 
204
 
</p>
205
 
<p>Relative path to filename can be used, remember however that this path will be relative
206
 
to <code>process.cwd()</code>.
207
 
 
208
 
</p>
209
 
<h2>fs.rename(path1, path2, [callback])<span><a class="mark" href="#fs_fs_rename_path1_path2_callback" id="fs_fs_rename_path1_path2_callback">#</a></span></h2>
210
 
<p>Asynchronous rename(2). No arguments other than a possible exception are given
211
 
to the completion callback.
212
 
 
213
 
</p>
214
 
<h2>fs.renameSync(path1, path2)<span><a class="mark" href="#fs_fs_renamesync_path1_path2" id="fs_fs_renamesync_path1_path2">#</a></span></h2>
215
 
<p>Synchronous rename(2).
216
 
 
217
 
</p>
218
 
<h2>fs.truncate(fd, len, [callback])<span><a class="mark" href="#fs_fs_truncate_fd_len_callback" id="fs_fs_truncate_fd_len_callback">#</a></span></h2>
219
 
<p>Asynchronous ftruncate(2). No arguments other than a possible exception are
220
 
given to the completion callback.
221
 
 
222
 
</p>
223
 
<h2>fs.truncateSync(fd, len)<span><a class="mark" href="#fs_fs_truncatesync_fd_len" id="fs_fs_truncatesync_fd_len">#</a></span></h2>
224
 
<p>Synchronous ftruncate(2).
225
 
 
226
 
</p>
227
 
<h2>fs.chown(path, uid, gid, [callback])<span><a class="mark" href="#fs_fs_chown_path_uid_gid_callback" id="fs_fs_chown_path_uid_gid_callback">#</a></span></h2>
228
 
<p>Asynchronous chown(2). No arguments other than a possible exception are given
229
 
to the completion callback.
230
 
 
231
 
</p>
232
 
<h2>fs.chownSync(path, uid, gid)<span><a class="mark" href="#fs_fs_chownsync_path_uid_gid" id="fs_fs_chownsync_path_uid_gid">#</a></span></h2>
233
 
<p>Synchronous chown(2).
234
 
 
235
 
</p>
236
 
<h2>fs.fchown(fd, uid, gid, [callback])<span><a class="mark" href="#fs_fs_fchown_fd_uid_gid_callback" id="fs_fs_fchown_fd_uid_gid_callback">#</a></span></h2>
237
 
<p>Asynchronous fchown(2). No arguments other than a possible exception are given
238
 
to the completion callback.
239
 
 
240
 
</p>
241
 
<h2>fs.fchownSync(fd, uid, gid)<span><a class="mark" href="#fs_fs_fchownsync_fd_uid_gid" id="fs_fs_fchownsync_fd_uid_gid">#</a></span></h2>
242
 
<p>Synchronous fchown(2).
243
 
 
244
 
</p>
245
 
<h2>fs.lchown(path, uid, gid, [callback])<span><a class="mark" href="#fs_fs_lchown_path_uid_gid_callback" id="fs_fs_lchown_path_uid_gid_callback">#</a></span></h2>
246
 
<p>Asynchronous lchown(2). No arguments other than a possible exception are given
247
 
to the completion callback.
248
 
 
249
 
</p>
250
 
<h2>fs.lchownSync(path, uid, gid)<span><a class="mark" href="#fs_fs_lchownsync_path_uid_gid" id="fs_fs_lchownsync_path_uid_gid">#</a></span></h2>
251
 
<p>Synchronous lchown(2).
252
 
 
253
 
</p>
254
 
<h2>fs.chmod(path, mode, [callback])<span><a class="mark" href="#fs_fs_chmod_path_mode_callback" id="fs_fs_chmod_path_mode_callback">#</a></span></h2>
255
 
<p>Asynchronous chmod(2). No arguments other than a possible exception are given
256
 
to the completion callback.
257
 
 
258
 
</p>
259
 
<h2>fs.chmodSync(path, mode)<span><a class="mark" href="#fs_fs_chmodsync_path_mode" id="fs_fs_chmodsync_path_mode">#</a></span></h2>
260
 
<p>Synchronous chmod(2).
261
 
 
262
 
</p>
263
 
<h2>fs.fchmod(fd, mode, [callback])<span><a class="mark" href="#fs_fs_fchmod_fd_mode_callback" id="fs_fs_fchmod_fd_mode_callback">#</a></span></h2>
264
 
<p>Asynchronous fchmod(2). No arguments other than a possible exception
265
 
are given to the completion callback.
266
 
 
267
 
</p>
268
 
<h2>fs.fchmodSync(fd, mode)<span><a class="mark" href="#fs_fs_fchmodsync_fd_mode" id="fs_fs_fchmodsync_fd_mode">#</a></span></h2>
269
 
<p>Synchronous fchmod(2).
270
 
 
271
 
</p>
272
 
<h2>fs.lchmod(path, mode, [callback])<span><a class="mark" href="#fs_fs_lchmod_path_mode_callback" id="fs_fs_lchmod_path_mode_callback">#</a></span></h2>
273
 
<p>Asynchronous lchmod(2). No arguments other than a possible exception
274
 
are given to the completion callback.
275
 
 
276
 
</p>
277
 
<h2>fs.lchmodSync(path, mode)<span><a class="mark" href="#fs_fs_lchmodsync_path_mode" id="fs_fs_lchmodsync_path_mode">#</a></span></h2>
278
 
<p>Synchronous lchmod(2).
279
 
 
280
 
</p>
281
 
<h2>fs.stat(path, [callback])<span><a class="mark" href="#fs_fs_stat_path_callback" id="fs_fs_stat_path_callback">#</a></span></h2>
282
 
<p>Asynchronous stat(2). The callback gets two arguments <code>(err, stats)</code> where
283
 
<code>stats</code> is a <a href="#fs_class_fs_stats">fs.Stats</a> object.  See the <a href="#fs_class_fs_stats">fs.Stats</a>
284
 
section below for more information.
285
 
 
286
 
</p>
287
 
<h2>fs.lstat(path, [callback])<span><a class="mark" href="#fs_fs_lstat_path_callback" id="fs_fs_lstat_path_callback">#</a></span></h2>
288
 
<p>Asynchronous lstat(2). The callback gets two arguments <code>(err, stats)</code> where
289
 
<code>stats</code> is a <code>fs.Stats</code> object. <code>lstat()</code> is identical to <code>stat()</code>, except that if
290
 
<code>path</code> is a symbolic link, then the link itself is stat-ed, not the file that it
291
 
refers to.
292
 
 
293
 
</p>
294
 
<h2>fs.fstat(fd, [callback])<span><a class="mark" href="#fs_fs_fstat_fd_callback" id="fs_fs_fstat_fd_callback">#</a></span></h2>
295
 
<p>Asynchronous fstat(2). The callback gets two arguments <code>(err, stats)</code> where
296
 
<code>stats</code> is a <code>fs.Stats</code> object. <code>fstat()</code> is identical to <code>stat()</code>, except that
297
 
the file to be stat-ed is specified by the file descriptor <code>fd</code>.
298
 
 
299
 
</p>
300
 
<h2>fs.statSync(path)<span><a class="mark" href="#fs_fs_statsync_path" id="fs_fs_statsync_path">#</a></span></h2>
301
 
<p>Synchronous stat(2). Returns an instance of <code>fs.Stats</code>.
302
 
 
303
 
</p>
304
 
<h2>fs.lstatSync(path)<span><a class="mark" href="#fs_fs_lstatsync_path" id="fs_fs_lstatsync_path">#</a></span></h2>
305
 
<p>Synchronous lstat(2). Returns an instance of <code>fs.Stats</code>.
306
 
 
307
 
</p>
308
 
<h2>fs.fstatSync(fd)<span><a class="mark" href="#fs_fs_fstatsync_fd" id="fs_fs_fstatsync_fd">#</a></span></h2>
309
 
<p>Synchronous fstat(2). Returns an instance of <code>fs.Stats</code>.
310
 
 
311
 
</p>
312
 
<h2>fs.link(srcpath, dstpath, [callback])<span><a class="mark" href="#fs_fs_link_srcpath_dstpath_callback" id="fs_fs_link_srcpath_dstpath_callback">#</a></span></h2>
313
 
<p>Asynchronous link(2). No arguments other than a possible exception are given to
314
 
the completion callback.
315
 
 
316
 
</p>
317
 
<h2>fs.linkSync(srcpath, dstpath)<span><a class="mark" href="#fs_fs_linksync_srcpath_dstpath" id="fs_fs_linksync_srcpath_dstpath">#</a></span></h2>
318
 
<p>Synchronous link(2).
319
 
 
320
 
</p>
321
 
<h2>fs.symlink(linkdata, path, [type], [callback])<span><a class="mark" href="#fs_fs_symlink_linkdata_path_type_callback" id="fs_fs_symlink_linkdata_path_type_callback">#</a></span></h2>
322
 
<p>Asynchronous symlink(2). No arguments other than a possible exception are given
323
 
to the completion callback.
324
 
<code>type</code> argument can be either <code>&apos;dir&apos;</code> or <code>&apos;file&apos;</code> (default is <code>&apos;file&apos;</code>).  It is only 
325
 
used on Windows (ignored on other platforms).
326
 
 
327
 
</p>
328
 
<h2>fs.symlinkSync(linkdata, path, [type])<span><a class="mark" href="#fs_fs_symlinksync_linkdata_path_type" id="fs_fs_symlinksync_linkdata_path_type">#</a></span></h2>
329
 
<p>Synchronous symlink(2).
330
 
 
331
 
</p>
332
 
<h2>fs.readlink(path, [callback])<span><a class="mark" href="#fs_fs_readlink_path_callback" id="fs_fs_readlink_path_callback">#</a></span></h2>
333
 
<p>Asynchronous readlink(2). The callback gets two arguments <code>(err,
334
 
linkString)</code>.
335
 
 
336
 
</p>
337
 
<h2>fs.readlinkSync(path)<span><a class="mark" href="#fs_fs_readlinksync_path" id="fs_fs_readlinksync_path">#</a></span></h2>
338
 
<p>Synchronous readlink(2). Returns the symbolic link&apos;s string value.
339
 
 
340
 
</p>
341
 
<h2>fs.realpath(path, [callback])<span><a class="mark" href="#fs_fs_realpath_path_callback" id="fs_fs_realpath_path_callback">#</a></span></h2>
342
 
<p>Asynchronous realpath(2).  The callback gets two arguments <code>(err,
343
 
resolvedPath)</code>.  May use <code>process.cwd</code> to resolve relative paths.
344
 
 
345
 
</p>
346
 
<h2>fs.realpathSync(path)<span><a class="mark" href="#fs_fs_realpathsync_path" id="fs_fs_realpathsync_path">#</a></span></h2>
347
 
<p>Synchronous realpath(2). Returns the resolved path.
348
 
 
349
 
</p>
350
 
<h2>fs.unlink(path, [callback])<span><a class="mark" href="#fs_fs_unlink_path_callback" id="fs_fs_unlink_path_callback">#</a></span></h2>
351
 
<p>Asynchronous unlink(2). No arguments other than a possible exception are given
352
 
to the completion callback.
353
 
 
354
 
</p>
355
 
<h2>fs.unlinkSync(path)<span><a class="mark" href="#fs_fs_unlinksync_path" id="fs_fs_unlinksync_path">#</a></span></h2>
356
 
<p>Synchronous unlink(2).
357
 
 
358
 
</p>
359
 
<h2>fs.rmdir(path, [callback])<span><a class="mark" href="#fs_fs_rmdir_path_callback" id="fs_fs_rmdir_path_callback">#</a></span></h2>
360
 
<p>Asynchronous rmdir(2). No arguments other than a possible exception are given
361
 
to the completion callback.
362
 
 
363
 
</p>
364
 
<h2>fs.rmdirSync(path)<span><a class="mark" href="#fs_fs_rmdirsync_path" id="fs_fs_rmdirsync_path">#</a></span></h2>
365
 
<p>Synchronous rmdir(2).
366
 
 
367
 
</p>
368
 
<h2>fs.mkdir(path, [mode], [callback])<span><a class="mark" href="#fs_fs_mkdir_path_mode_callback" id="fs_fs_mkdir_path_mode_callback">#</a></span></h2>
369
 
<p>Asynchronous mkdir(2). No arguments other than a possible exception are given
370
 
to the completion callback. <code>mode</code> defaults to <code>0777</code>.
371
 
 
372
 
</p>
373
 
<h2>fs.mkdirSync(path, [mode])<span><a class="mark" href="#fs_fs_mkdirsync_path_mode" id="fs_fs_mkdirsync_path_mode">#</a></span></h2>
374
 
<p>Synchronous mkdir(2).
375
 
 
376
 
</p>
377
 
<h2>fs.readdir(path, [callback])<span><a class="mark" href="#fs_fs_readdir_path_callback" id="fs_fs_readdir_path_callback">#</a></span></h2>
378
 
<p>Asynchronous readdir(3).  Reads the contents of a directory.
379
 
The callback gets two arguments <code>(err, files)</code> where <code>files</code> is an array of
380
 
the names of the files in the directory excluding <code>&apos;.&apos;</code> and <code>&apos;..&apos;</code>.
381
 
 
382
 
</p>
383
 
<h2>fs.readdirSync(path)<span><a class="mark" href="#fs_fs_readdirsync_path" id="fs_fs_readdirsync_path">#</a></span></h2>
384
 
<p>Synchronous readdir(3). Returns an array of filenames excluding <code>&apos;.&apos;</code> and
385
 
<code>&apos;..&apos;</code>.
386
 
 
387
 
</p>
388
 
<h2>fs.close(fd, [callback])<span><a class="mark" href="#fs_fs_close_fd_callback" id="fs_fs_close_fd_callback">#</a></span></h2>
389
 
<p>Asynchronous close(2).  No arguments other than a possible exception are given
390
 
to the completion callback.
391
 
 
392
 
</p>
393
 
<h2>fs.closeSync(fd)<span><a class="mark" href="#fs_fs_closesync_fd" id="fs_fs_closesync_fd">#</a></span></h2>
394
 
<p>Synchronous close(2).
395
 
 
396
 
</p>
397
 
<h2>fs.open(path, flags, [mode], [callback])<span><a class="mark" href="#fs_fs_open_path_flags_mode_callback" id="fs_fs_open_path_flags_mode_callback">#</a></span></h2>
398
 
<p>Asynchronous file open. See open(2). <code>flags</code> can be:
399
 
 
400
 
</p>
401
 
<ul>
402
 
<li><p><code>&apos;r&apos;</code> - Open file for reading.
403
 
An exception occurs if the file does not exist.</p>
404
 
</li>
405
 
<li><p><code>&apos;r+&apos;</code> - Open file for reading and writing.
406
 
An exception occurs if the file does not exist.</p>
407
 
</li>
408
 
<li><p><code>&apos;w&apos;</code> - Open file for writing.
409
 
The file is created (if it does not exist) or truncated (if it exists).</p>
410
 
</li>
411
 
<li><p><code>&apos;w+&apos;</code> - Open file for reading and writing.
412
 
The file is created (if it does not exist) or truncated (if it exists).</p>
413
 
</li>
414
 
<li><p><code>&apos;a&apos;</code> - Open file for appending.
415
 
The file is created if it does not exist.</p>
416
 
</li>
417
 
<li><p><code>&apos;a+&apos;</code> - Open file for reading and appending.
418
 
The file is created if it does not exist.</p>
419
 
</li>
420
 
</ul>
421
 
<p><code>mode</code> defaults to <code>0666</code>. The callback gets two arguments <code>(err, fd)</code>.
422
 
 
423
 
</p>
424
 
<h2>fs.openSync(path, flags, [mode])<span><a class="mark" href="#fs_fs_opensync_path_flags_mode" id="fs_fs_opensync_path_flags_mode">#</a></span></h2>
425
 
<p>Synchronous open(2).
426
 
 
427
 
</p>
428
 
<h2>fs.utimes(path, atime, mtime, [callback])<span><a class="mark" href="#fs_fs_utimes_path_atime_mtime_callback" id="fs_fs_utimes_path_atime_mtime_callback">#</a></span></h2>
429
 
<h2>fs.utimesSync(path, atime, mtime)<span><a class="mark" href="#fs_fs_utimessync_path_atime_mtime" id="fs_fs_utimessync_path_atime_mtime">#</a></span></h2>
430
 
<p>Change file timestamps of the file referenced by the supplied path.
431
 
 
432
 
</p>
433
 
<h2>fs.futimes(fd, atime, mtime, [callback])<span><a class="mark" href="#fs_fs_futimes_fd_atime_mtime_callback" id="fs_fs_futimes_fd_atime_mtime_callback">#</a></span></h2>
434
 
<h2>fs.futimesSync(fd, atime, mtime)<span><a class="mark" href="#fs_fs_futimessync_fd_atime_mtime" id="fs_fs_futimessync_fd_atime_mtime">#</a></span></h2>
435
 
<p>Change the file timestamps of a file referenced by the supplied file
436
 
descriptor.
437
 
 
438
 
</p>
439
 
<h2>fs.fsync(fd, [callback])<span><a class="mark" href="#fs_fs_fsync_fd_callback" id="fs_fs_fsync_fd_callback">#</a></span></h2>
440
 
<p>Asynchronous fsync(2). No arguments other than a possible exception are given
441
 
to the completion callback.
442
 
 
443
 
</p>
444
 
<h2>fs.fsyncSync(fd)<span><a class="mark" href="#fs_fs_fsyncsync_fd" id="fs_fs_fsyncsync_fd">#</a></span></h2>
445
 
<p>Synchronous fsync(2).
446
 
 
447
 
</p>
448
 
<h2>fs.write(fd, buffer, offset, length, position, [callback])<span><a class="mark" href="#fs_fs_write_fd_buffer_offset_length_position_callback" id="fs_fs_write_fd_buffer_offset_length_position_callback">#</a></span></h2>
449
 
<p>Write <code>buffer</code> to the file specified by <code>fd</code>.
450
 
 
451
 
</p>
452
 
<p><code>offset</code> and <code>length</code> determine the part of the buffer to be written.
453
 
 
454
 
</p>
455
 
<p><code>position</code> refers to the offset from the beginning of the file where this data
456
 
should be written. If <code>position</code> is <code>null</code>, the data will be written at the
457
 
current position.
458
 
See pwrite(2).
459
 
 
460
 
</p>
461
 
<p>The callback will be given three arguments <code>(err, written, buffer)</code> where <code>written</code>
462
 
specifies how many <em>bytes</em> were written from <code>buffer</code>.
463
 
 
464
 
</p>
465
 
<p>Note that it is unsafe to use <code>fs.write</code> multiple times on the same file
466
 
without waiting for the callback. For this scenario,
467
 
<code>fs.createWriteStream</code> is strongly recommended.
468
 
 
469
 
</p>
470
 
<h2>fs.writeSync(fd, buffer, offset, length, position)<span><a class="mark" href="#fs_fs_writesync_fd_buffer_offset_length_position" id="fs_fs_writesync_fd_buffer_offset_length_position">#</a></span></h2>
471
 
<p>Synchronous version of buffer-based <code>fs.write()</code>. Returns the number of bytes
472
 
written.
473
 
 
474
 
</p>
475
 
<h2>fs.writeSync(fd, str, position, [encoding])<span><a class="mark" href="#fs_fs_writesync_fd_str_position_encoding" id="fs_fs_writesync_fd_str_position_encoding">#</a></span></h2>
476
 
<p>Synchronous version of string-based <code>fs.write()</code>. <code>encoding</code> defaults to
477
 
<code>&apos;utf8&apos;</code>. Returns the number of <em>bytes</em> written.
478
 
 
479
 
</p>
480
 
<h2>fs.read(fd, buffer, offset, length, position, [callback])<span><a class="mark" href="#fs_fs_read_fd_buffer_offset_length_position_callback" id="fs_fs_read_fd_buffer_offset_length_position_callback">#</a></span></h2>
481
 
<p>Read data from the file specified by <code>fd</code>.
482
 
 
483
 
</p>
484
 
<p><code>buffer</code> is the buffer that the data will be written to.
485
 
 
486
 
</p>
487
 
<p><code>offset</code> is offset within the buffer where writing will start.
488
 
 
489
 
</p>
490
 
<p><code>length</code> is an integer specifying the number of bytes to read.
491
 
 
492
 
</p>
493
 
<p><code>position</code> is an integer specifying where to begin reading from in the file.
494
 
If <code>position</code> is <code>null</code>, data will be read from the current file position.
495
 
 
496
 
</p>
497
 
<p>The callback is given the three arguments, <code>(err, bytesRead, buffer)</code>.
498
 
 
499
 
</p>
500
 
<h2>fs.readSync(fd, buffer, offset, length, position)<span><a class="mark" href="#fs_fs_readsync_fd_buffer_offset_length_position" id="fs_fs_readsync_fd_buffer_offset_length_position">#</a></span></h2>
501
 
<p>Synchronous version of buffer-based <code>fs.read</code>. Returns the number of
502
 
<code>bytesRead</code>.
503
 
 
504
 
</p>
505
 
<h2>fs.readSync(fd, length, position, encoding)<span><a class="mark" href="#fs_fs_readsync_fd_length_position_encoding" id="fs_fs_readsync_fd_length_position_encoding">#</a></span></h2>
506
 
<p>Synchronous version of string-based <code>fs.read</code>. Returns the number of
507
 
<code>bytesRead</code>.
508
 
 
509
 
</p>
510
 
<h2>fs.readFile(filename, [encoding], [callback])<span><a class="mark" href="#fs_fs_readfile_filename_encoding_callback" id="fs_fs_readfile_filename_encoding_callback">#</a></span></h2>
511
 
<p>Asynchronously reads the entire contents of a file. Example:
512
 
 
513
 
</p>
514
 
<pre><code>fs.readFile(&apos;/etc/passwd&apos;, function (err, data) {
515
 
  if (err) throw err;
516
 
  console.log(data);
517
 
});</code></pre>
518
 
<p>The callback is passed two arguments <code>(err, data)</code>, where <code>data</code> is the
519
 
contents of the file.
520
 
 
521
 
</p>
522
 
<p>If no encoding is specified, then the raw buffer is returned.
523
 
 
524
 
 
525
 
</p>
526
 
<h2>fs.readFileSync(filename, [encoding])<span><a class="mark" href="#fs_fs_readfilesync_filename_encoding" id="fs_fs_readfilesync_filename_encoding">#</a></span></h2>
527
 
<p>Synchronous version of <code>fs.readFile</code>. Returns the contents of the <code>filename</code>.
528
 
 
529
 
</p>
530
 
<p>If <code>encoding</code> is specified then this function returns a string. Otherwise it
531
 
returns a buffer.
532
 
 
533
 
 
534
 
</p>
535
 
<h2>fs.writeFile(filename, data, [encoding], [callback])<span><a class="mark" href="#fs_fs_writefile_filename_data_encoding_callback" id="fs_fs_writefile_filename_data_encoding_callback">#</a></span></h2>
536
 
<p>Asynchronously writes data to a file, replacing the file if it already exists.
537
 
<code>data</code> can be a string or a buffer. The <code>encoding</code> argument is ignored if
538
 
<code>data</code> is a buffer. It defaults to <code>&apos;utf8&apos;</code>.
539
 
 
540
 
</p>
541
 
<p>Example:
542
 
 
543
 
</p>
544
 
<pre><code>fs.writeFile(&apos;message.txt&apos;, &apos;Hello Node&apos;, function (err) {
545
 
  if (err) throw err;
546
 
  console.log(&apos;It\&apos;s saved!&apos;);
547
 
});</code></pre>
548
 
<h2>fs.writeFileSync(filename, data, [encoding])<span><a class="mark" href="#fs_fs_writefilesync_filename_data_encoding" id="fs_fs_writefilesync_filename_data_encoding">#</a></span></h2>
549
 
<p>The synchronous version of <code>fs.writeFile</code>.
550
 
 
551
 
</p>
552
 
<h2>fs.watchFile(filename, [options], listener)<span><a class="mark" href="#fs_fs_watchfile_filename_options_listener" id="fs_fs_watchfile_filename_options_listener">#</a></span></h2>
553
 
<pre><code>Stability: 2 - Unstable.  Use fs.watch instead, if available.</code></pre>
554
 
<p>Watch for changes on <code>filename</code>. The callback <code>listener</code> will be called each
555
 
time the file is accessed.
556
 
 
557
 
</p>
558
 
<p>The second argument is optional. The <code>options</code> if provided should be an object
559
 
containing two members a boolean, <code>persistent</code>, and <code>interval</code>. <code>persistent</code>
560
 
indicates whether the process should continue to run as long as files are
561
 
being watched. <code>interval</code> indicates how often the target should be polled,
562
 
in milliseconds. (On Linux systems with inotify, <code>interval</code> is ignored.) The
563
 
default is <code>{ persistent: true, interval: 0 }</code>.
564
 
 
565
 
</p>
566
 
<p>The <code>listener</code> gets two arguments the current stat object and the previous
567
 
stat object:
568
 
 
569
 
</p>
570
 
<pre><code>fs.watchFile(&apos;message.text&apos;, function (curr, prev) {
571
 
  console.log(&apos;the current mtime is: &apos; + curr.mtime);
572
 
  console.log(&apos;the previous mtime was: &apos; + prev.mtime);
573
 
});</code></pre>
574
 
<p>These stat objects are instances of <code>fs.Stat</code>.
575
 
 
576
 
</p>
577
 
<p>If you want to be notified when the file was modified, not just accessed
578
 
you need to compare <code>curr.mtime</code> and <code>prev.mtime</code>.
579
 
 
580
 
 
581
 
</p>
582
 
<h2>fs.unwatchFile(filename)<span><a class="mark" href="#fs_fs_unwatchfile_filename" id="fs_fs_unwatchfile_filename">#</a></span></h2>
583
 
<pre><code>Stability: 2 - Unstable.  Use fs.watch instead, if available.</code></pre>
584
 
<p>Stop watching for changes on <code>filename</code>.
585
 
 
586
 
</p>
587
 
<h2>fs.watch(filename, [options], listener)<span><a class="mark" href="#fs_fs_watch_filename_options_listener" id="fs_fs_watch_filename_options_listener">#</a></span></h2>
588
 
<pre><code>Stability: 2 - Unstable.  Not available on all platforms.</code></pre>
589
 
<p>Watch for changes on <code>filename</code>, where <code>filename</code> is either a file or a
590
 
directory.  The returned object is a <a href="#fs_class_fs_fswatcher">fs.FSWatcher</a>.
591
 
 
592
 
</p>
593
 
<p>The second argument is optional. The <code>options</code> if provided should be an object
594
 
containing a boolean member <code>persistent</code>, which indicates whether the process
595
 
should continue to run as long as files are being watched. The default is
596
 
<code>{ persistent: true }</code>.
597
 
 
598
 
</p>
599
 
<p>The listener callback gets two arguments <code>(event, filename)</code>.  <code>event</code> is either
600
 
&apos;rename&apos; or &apos;change&apos;, and <code>filename</code> is the name of the file which triggered
601
 
the event.
602
 
 
603
 
</p>
604
 
<h3>Caveats<span><a class="mark" href="#fs_caveats" id="fs_caveats">#</a></span></h3>
605
 
<!--type=misc-->
606
 
 
607
 
<p>The <code>fs.watch</code> API is not 100% consistent across platforms, and is
608
 
unavailable in some situations.
609
 
 
610
 
</p>
611
 
<h4>Availability<span><a class="mark" href="#fs_availability" id="fs_availability">#</a></span></h4>
612
 
<!--type=misc-->
613
 
 
614
 
<p>This feature depends on the underlying operating system providing a way
615
 
to be notified of filesystem changes.
616
 
 
617
 
</p>
618
 
<ul>
619
 
<li>On Linux systems, this uses <code>inotify</code>.</li>
620
 
<li>On BSD systems (including OS X), this uses <code>kqueue</code>.</li>
621
 
<li>On SunOS systems (including Solaris and SmartOS), this uses <code>event ports</code>.</li>
622
 
<li>On Windows systems, this feature depends on <code>ReadDirectoryChangesW</code>.</li>
623
 
</ul>
624
 
<p>If the underlying functionality is not available for some reason, then
625
 
<code>fs.watch</code> will not be able to function.  You can still use
626
 
<code>fs.watchFile</code>, which uses stat polling, but it is slower and less
627
 
reliable.
628
 
 
629
 
</p>
630
 
<h4>Filename Argument<span><a class="mark" href="#fs_filename_argument" id="fs_filename_argument">#</a></span></h4>
631
 
<!--type=misc-->
632
 
 
633
 
<p>Providing <code>filename</code> argument in the callback is not supported
634
 
on every platform (currently it&apos;s only supported on Linux and Windows).  Even
635
 
on supported platforms <code>filename</code> is not always guaranteed to be provided.
636
 
Therefore, don&apos;t assume that <code>filename</code> argument is always provided in the
637
 
callback, and have some fallback logic if it is null.
638
 
 
639
 
</p>
640
 
<pre><code>fs.watch(&apos;somedir&apos;, function (event, filename) {
641
 
  console.log(&apos;event is: &apos; + event);
642
 
  if (filename) {
643
 
    console.log(&apos;filename provided: &apos; + filename);
644
 
  } else {
645
 
    console.log(&apos;filename not provided&apos;);
646
 
  }
647
 
});</code></pre>
648
 
<h2>Class: fs.Stats<span><a class="mark" href="#fs_class_fs_stats" id="fs_class_fs_stats">#</a></span></h2>
649
 
<p>Objects returned from <code>fs.stat()</code>, <code>fs.lstat()</code> and <code>fs.fstat()</code> and their
650
 
synchronous counterparts are of this type.
651
 
 
652
 
</p>
653
 
<ul>
654
 
<li><code>stats.isFile()</code></li>
655
 
<li><code>stats.isDirectory()</code></li>
656
 
<li><code>stats.isBlockDevice()</code></li>
657
 
<li><code>stats.isCharacterDevice()</code></li>
658
 
<li><code>stats.isSymbolicLink()</code> (only valid with  <code>fs.lstat()</code>)</li>
659
 
<li><code>stats.isFIFO()</code></li>
660
 
<li><code>stats.isSocket()</code></li>
661
 
</ul>
662
 
<p>For a regular file <code>util.inspect(stats)</code> would return a string very
663
 
similar to this:
664
 
 
665
 
</p>
666
 
<pre><code>{ dev: 2114,
667
 
  ino: 48064969,
668
 
  mode: 33188,
669
 
  nlink: 1,
670
 
  uid: 85,
671
 
  gid: 100,
672
 
  rdev: 0,
673
 
  size: 527,
674
 
  blksize: 4096,
675
 
  blocks: 8,
676
 
  atime: Mon, 10 Oct 2011 23:24:11 GMT,
677
 
  mtime: Mon, 10 Oct 2011 23:24:11 GMT,
678
 
  ctime: Mon, 10 Oct 2011 23:24:11 GMT }</code></pre>
679
 
<p>Please note that <code>atime</code>, <code>mtime</code> and <code>ctime</code> are instances
680
 
of <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date">Date</a> object and to compare the values of
681
 
these objects you should use appropriate methods. For most
682
 
general uses <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/getTime">getTime()</a> will return
683
 
the number of milliseconds elapsed since <em>1 January 1970
684
 
00:00:00 UTC</em> and this integer should be sufficient for
685
 
any comparison, however there additional methods which can
686
 
be used for displaying fuzzy information. More details can
687
 
be found in the <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date">MDN JavaScript Reference</a> page.
688
 
 
689
 
</p>
690
 
<h2>fs.createReadStream(path, [options])<span><a class="mark" href="#fs_fs_createreadstream_path_options" id="fs_fs_createreadstream_path_options">#</a></span></h2>
691
 
<p>Returns a new ReadStream object (See <code>Readable Stream</code>).
692
 
 
693
 
</p>
694
 
<p><code>options</code> is an object with the following defaults:
695
 
 
696
 
</p>
697
 
<pre><code>{ flags: &apos;r&apos;,
698
 
  encoding: null,
699
 
  fd: null,
700
 
  mode: 0666,
701
 
  bufferSize: 64 * 1024
702
 
}</code></pre>
703
 
<p><code>options</code> can include <code>start</code> and <code>end</code> values to read a range of bytes from
704
 
the file instead of the entire file.  Both <code>start</code> and <code>end</code> are inclusive and
705
 
start at 0.
706
 
 
707
 
</p>
708
 
<p>An example to read the last 10 bytes of a file which is 100 bytes long:
709
 
 
710
 
</p>
711
 
<pre><code>fs.createReadStream(&apos;sample.txt&apos;, {start: 90, end: 99});</code></pre>
712
 
<h2>Class: fs.ReadStream<span><a class="mark" href="#fs_class_fs_readstream" id="fs_class_fs_readstream">#</a></span></h2>
713
 
<p><code>ReadStream</code> is a <a href="stream.html#stream_readable_stream">Readable Stream</a>.
714
 
 
715
 
</p>
716
 
<h3>Event: &apos;open&apos;<span><a class="mark" href="#fs_event_open" id="fs_event_open">#</a></span></h3>
717
 
<div class="signature"><ul>
718
 
<li><code>fd</code> <span class="type">Integer</span> file descriptor used by the ReadStream.</li>
719
 
</div></ul>
720
 
<p>Emitted when the ReadStream&apos;s file is opened.
721
 
 
722
 
 
723
 
</p>
724
 
<h2>fs.createWriteStream(path, [options])<span><a class="mark" href="#fs_fs_createwritestream_path_options" id="fs_fs_createwritestream_path_options">#</a></span></h2>
725
 
<p>Returns a new WriteStream object (See <code>Writable Stream</code>).
726
 
 
727
 
</p>
728
 
<p><code>options</code> is an object with the following defaults:
729
 
 
730
 
</p>
731
 
<pre><code>{ flags: &apos;w&apos;,
732
 
  encoding: null,
733
 
  mode: 0666 }</code></pre>
734
 
<p><code>options</code> may also include a <code>start</code> option to allow writing data at
735
 
some position past the beginning of the file.  Modifying a file rather
736
 
than replacing it may require a <code>flags</code> mode of <code>r+</code> rather than the
737
 
default mode <code>w</code>.
738
 
 
739
 
</p>
740
 
<h2>fs.WriteStream<span><a class="mark" href="#fs_fs_writestream" id="fs_fs_writestream">#</a></span></h2>
741
 
<p><code>WriteStream</code> is a <a href="stream.html#stream_writable_stream">Writable Stream</a>.
742
 
 
743
 
</p>
744
 
<h3>Event: &apos;open&apos;<span><a class="mark" href="#fs_event_open_1" id="fs_event_open_1">#</a></span></h3>
745
 
<div class="signature"><ul>
746
 
<li><code>fd</code> <span class="type">Integer</span> file descriptor used by the ReadStream.</li>
747
 
</div></ul>
748
 
<p>Emitted when the WriteStream&apos;s file is opened.
749
 
 
750
 
</p>
751
 
<h3>file.bytesWritten<span><a class="mark" href="#fs_file_byteswritten" id="fs_file_byteswritten">#</a></span></h3>
752
 
<p>The number of bytes written so far. Does not include data that is still queued
753
 
for writing.
754
 
 
755
 
</p>
756
 
<h2>Class: fs.FSWatcher<span><a class="mark" href="#fs_class_fs_fswatcher" id="fs_class_fs_fswatcher">#</a></span></h2>
757
 
<p>Objects returned from <code>fs.watch()</code> are of this type.
758
 
 
759
 
</p>
760
 
<h3>watcher.close()<span><a class="mark" href="#fs_watcher_close" id="fs_watcher_close">#</a></span></h3>
761
 
<p>Stop watching for changes on the given <code>fs.FSWatcher</code>.
762
 
 
763
 
</p>
764
 
<h3>Event: &apos;change&apos;<span><a class="mark" href="#fs_event_change" id="fs_event_change">#</a></span></h3>
765
 
<div class="signature"><ul>
766
 
<li><code>event</code> <span class="type">String</span> The type of fs change</li>
767
 
<li><code>filename</code> <span class="type">String</span> The filename that changed (if relevant/available)</li>
768
 
</div></ul>
769
 
<p>Emitted when something changes in a watched directory or file.
770
 
See more details in <a href="#fs_fs_watch_filename_options_listener">fs.watch</a>.
771
 
 
772
 
</p>
773
 
<h3>Event: &apos;error&apos;<span><a class="mark" href="#fs_event_error" id="fs_event_error">#</a></span></h3>
774
 
<div class="signature"><ul>
775
 
<li><code>error</code> <span class="type">Error object</span></li>
776
 
</div></ul>
777
 
<p>Emitted when an error occurs.
778
 
</p>
779
 
 
780
 
          </div>
781
 
        </div>
782
 
    </div>
783
 
    <div id="footer">
784
 
        <ul class="clearfix">
785
 
            <li><a href="/">Node.js</a></li>
786
 
            <li><a href="/#download">Download</a></li>
787
 
            <li><a href="/about/">About</a></li>
788
 
            <li><a href="http://search.npmjs.org/">npm Registry</a></li>
789
 
            <li><a href="http://nodejs.org/api/">Docs</a></li>
790
 
            <li><a href="http://blog.nodejs.org">Blog</a></li>
791
 
            <li><a href="/community/">Community</a></li>
792
 
            <li><a href="/logos/">Logos</a></li>
793
 
            <li><a href="http://jobs.nodejs.org/">Jobs</a></li>
794
 
            <li><a href="http://twitter.com/nodejs" class="twitter">@nodejs</a></li>
795
 
        </ul>
796
 
 
797
 
        <p>Copyright <a href="http://joyent.com">Joyent, Inc</a>, Node.js is a <a href="/trademark-policy.pdf">trademark</a> of Joyent, Inc. View <a href="https://raw.github.com/joyent/node/v0.6.18/LICENSE">license</a>.</p>
798
 
    </div>
799
 
 
800
 
  <script src="../sh_main.js"></script>
801
 
  <script src="../sh_javascript.min.js"></script>
802
 
  <script>highlight(undefined, undefined, 'pre');</script>
803
 
  <script>
804
 
    var gaJsHost = (("https:" == document.location.protocol) ?
805
 
    "https://ssl." : "http://www.");
806
 
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
807
 
  </script>
808
 
  <script>
809
 
    try {
810
 
      var pageTracker = _gat._getTracker("UA-10874194-2");
811
 
      pageTracker._trackPageview();
812
 
      } catch(err) {}</script>
813
 
</body>
814
 
</html>
815