5 The following shows fs module APIs available for each platform.
7 | | Linux<br/>(Ubuntu) | Raspbian<br/>(Raspberry Pi) | Nuttx<br/>(STM32F4-Discovery) |
8 | :---: | :---: | :---: | :---: |
9 | fs.close | O | O | O |
10 | fs.closeSync | O | O | O |
11 | fs.open | O | O | O |
12 | fs.openSync | O | O | O |
13 | fs.read | O | O | O |
14 | fs.readSync | O | O | O |
15 | fs.readDir | O | O | X |
16 | fs.readDirSync | O | O | X |
17 | fs.readFile | O | O | O |
18 | fs.readFileSync | O | O | O |
19 | fs.rename | O | O | O |
20 | fs.renameSync | O | O | O |
21 | fs.stat | O | O | O |
22 | fs.statSync | O | O | O |
23 | fs.fstat | O | O | O |
24 | fs.fstatSync | O | O | O |
25 | fs.write | O | O | O |
26 | fs.writeSync | O | O | O |
27 | fs.writeFile | O | O | O |
28 | fs.writeFileSync | O | O | O |
29 | fs.unlink | O | O | O |
30 | fs.unlinkSync | O | O | O |
32 ※ On `nuttx` path should be passed with a form of **absolute path**.
37 #### fs.close(fd, callback)
39 * `fd: Int` - file descriptor.
40 * `callback: Function(err) `
43 Closes the file of fd asynchronously.
48 * `fd: Int` - file descriptor.
50 Closes the file of fd synchronously.
53 #### fs.open(path, flags[, mode], callback)
55 * `path: String` - file path to be opened.
56 * `flags: String` - open flags.
57 * `mode: Number`, Default: `0666` - permission mode.
58 * `callback: Function(err, fd)`
59 * `err: Error` - `Error` object if there was something wrong, otherwise `null`.
60 * `fd: Number` - file descriptor.
63 #### fs.openSync(path, flags[, mode])
65 * `path: String` - file path to be opened.
66 * `flags: String` - open flags.
67 * `mode: Number`, Default: `0666` - permission mode.
70 #### fs.read(fd, buffer, offset, length, position, callback)
72 * `fd: Int` - file descriptor.
73 * `buffer: Buffer` - buffer that the data will be written to.
74 * `offset: Number` - offset of the buffer where to start writing.
75 * `length: Number` - number of bytes to read.
76 * `position: Number` - specifying where to start read data from the file, if `null`, read from current position.
77 * `callback: Function(err, bytesRead, buffer) `
83 #### fs.readSync(fd, buffer, offset, length, position)
85 * `fd: Int` - file descriptor.
86 * `buffer: Buffer` - buffer that the data will be written to.
87 * `offset: Number` - offset of the buffer where to start writing.
88 * `length: Number` - number of bytes to read.
89 * `position: Number` - specifying where to start read data from the file, if `null`, read from current position.
92 #### fs.readFile(path[, options], callback)
94 * `path: String` - file path to be opened.
95 * `options: Object` - options for the operation.
96 * `encoding: String`, Default: `null` - encoding of the file.
97 * `flag: String`, Default: `r` - file open flag.
98 * `callback: Function(err, data)` - callback function.
102 Reads entire file asynchronously.
105 #### fs.readFileSync(path[, options])
107 * `path: String` - file path to be opened.
108 * `options: Object` - options for the operation.
109 * `encoding: String`, Default: `null` - encoding of the file.
110 * `flag: String`, Default: `r` - file open flag.
112 Reads entire file synchronously.
115 #### fs.rename(oldPath, newPath, callback)
117 * `oldPath: String` - old file path
118 * `newPath: String` - new file path
119 * `callback: Function(err)` - callback function.
122 Renames `oldPath` to `newPath` asynchronously.
125 #### fs.renameSync(oldPath, newPath)
127 * `oldPath: String` - old file path
128 * `newPath: String` - new file path
130 Renames `oldPath` to `newPath` synchronously.
133 #### fs.stat(path, callback)
135 * `path: String` - file path to be stated
136 * callback: Function(err, stat)` - callback function.
141 #### fs.statSync(path)
143 * `path: String` - file path to be stated
146 #### fs.fstat(fd, callback)
148 * `fd: Number` - file descriptor to be stated
149 * callback: Function(err, stat)` - callback function.
154 #### fs.fstatSync(fd)
156 * `fd: Number` - file descriptor to be stated
160 fs.Stats class is a object returned from ```fs.stat()```,```fs.fstat()``` and their synchronous counterparts.
164 #### stats.isDirectory()
166 Returns true if stated file is a directory
170 Returns true if stated file is a file
173 #### fs.write(fd, buffer, offset, length, position, callback)
175 * `fd: Int` - file descriptor.
176 * `buffer: Buffer` - buffer that the data will be written from.
177 * `offset: Number` - offset of the buffer where from start reading.
178 * `length: Number` - number of bytes to write.
179 * `position: Number` - specifying where to start write data to the file, if `null`, read from current position.
180 * callback: Function(err, bytesWrite)` - callback function.
185 #### fs.writeSync(fd, buffer, offset, length, position)
187 * `fd: Int` - file descriptor.
188 * `buffer: Buffer` - buffer that the data will be written from.
189 * `offset: Number` - offset of the buffer where from start reading.
190 * `length: Number` - number of bytes to write.
191 * `position: Number` - specifying where to start write data to the file, if `null`, read from current position.
194 #### fs.writeFile(path, data, [, options], callback)
196 * `path: String` - file path that the `data` will be written
197 * `data: Buffer` - buffer that contains data
198 * `options: Object` - options for the operation
199 * `callback: Function(err)` - callback function
202 Writes entire `data` to the file specified by `path` asynchronously.
205 #### fs.writeFileSync(path, data, [, options])
207 * `path: String` - file path that the `data` will be written
208 * `data: Buffer` - buffer that contains data
209 * `options: Object` - options for the operation
211 Writes entire `data` to the file specified by `path` synchronously.
214 #### fs.unlink(path, callback)
216 * `path: String` - file path to be removed
217 * `callback: Function(err) `
220 Removes the file specified by `path` asynchronously.
223 #### fs.unlinkSync(path)
225 * `path: String` - file path to be removed
227 Removes the file specified by `path` synchronously.