|
@ -174,7 +174,7 @@ process.watchFile(f, function (curr, prev) { |
|
|
}); |
|
|
}); |
|
|
------------------------- |
|
|
------------------------- |
|
|
+ |
|
|
+ |
|
|
These stat objects are instances of +posix.Stat+. |
|
|
These stat objects are instances of +fs.Stat+. |
|
|
|
|
|
|
|
|
+process.unwatchFile(filename)+:: |
|
|
+process.unwatchFile(filename)+:: |
|
|
Stop watching for changes on +filename+. |
|
|
Stop watching for changes on +filename+. |
|
@ -609,16 +609,16 @@ will be sent +"SIGTERM"+. See signal(7) for a list of available signals. |
|
|
=== POSIX module |
|
|
=== POSIX module |
|
|
|
|
|
|
|
|
File I/O is provided by simple wrappers around standard POSIX functions. To |
|
|
File I/O is provided by simple wrappers around standard POSIX functions. To |
|
|
use this module do +require("posix")+. |
|
|
use this module do +require("fs")+. |
|
|
|
|
|
|
|
|
All POSIX wrappers have a similar form. They return a promise |
|
|
All POSIX wrappers have a similar form. They return a promise |
|
|
(+events.Promise+). Example of deleting a file: |
|
|
(+events.Promise+). Example of deleting a file: |
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------ |
|
|
------------------------------------------------------------------------------ |
|
|
var posix = require("posix"), |
|
|
var fs = require("fs"), |
|
|
sys = require("sys"); |
|
|
sys = require("sys"); |
|
|
|
|
|
|
|
|
var promise = posix.unlink("/tmp/hello"); |
|
|
var promise = fs.unlink("/tmp/hello"); |
|
|
|
|
|
|
|
|
promise.addCallback(function () { |
|
|
promise.addCallback(function () { |
|
|
sys.puts("successfully deleted /tmp/hello"); |
|
|
sys.puts("successfully deleted /tmp/hello"); |
|
@ -629,8 +629,8 @@ There is no guaranteed ordering to the POSIX wrappers. The |
|
|
following is very much prone to error |
|
|
following is very much prone to error |
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------ |
|
|
------------------------------------------------------------------------------ |
|
|
posix.rename("/tmp/hello", "/tmp/world"); |
|
|
fs.rename("/tmp/hello", "/tmp/world"); |
|
|
posix.stat("/tmp/world").addCallback(function (stats) { |
|
|
fs.stat("/tmp/world").addCallback(function (stats) { |
|
|
sys.puts("stats: " + JSON.stringify(stats)); |
|
|
sys.puts("stats: " + JSON.stringify(stats)); |
|
|
}); |
|
|
}); |
|
|
------------------------------------------------------------------------------ |
|
|
------------------------------------------------------------------------------ |
|
@ -639,8 +639,8 @@ It could be that +stat()+ is executed before the +rename()+. |
|
|
The correct way to do this is to chain the promises. |
|
|
The correct way to do this is to chain the promises. |
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------ |
|
|
------------------------------------------------------------------------------ |
|
|
posix.rename("/tmp/hello", "/tmp/world").addCallback(function () { |
|
|
fs.rename("/tmp/hello", "/tmp/world").addCallback(function () { |
|
|
posix.stat("/tmp/world").addCallback(function (stats) { |
|
|
fs.stat("/tmp/world").addCallback(function (stats) { |
|
|
sys.puts("stats: " + JSON.stringify(stats)); |
|
|
sys.puts("stats: " + JSON.stringify(stats)); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
@ -649,25 +649,25 @@ posix.rename("/tmp/hello", "/tmp/world").addCallback(function () { |
|
|
Or use the +promise.wait()+ functionality: |
|
|
Or use the +promise.wait()+ functionality: |
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------ |
|
|
------------------------------------------------------------------------------ |
|
|
posix.rename("/tmp/hello", "/tmp/world").wait(); |
|
|
fs.rename("/tmp/hello", "/tmp/world").wait(); |
|
|
var stats = posix.stat("/tmp/world").wait(); |
|
|
var stats = fs.stat("/tmp/world").wait(); |
|
|
sys.puts("stats: " + JSON.stringify(stats)); |
|
|
sys.puts("stats: " + JSON.stringify(stats)); |
|
|
------------------------------------------------------------------------------ |
|
|
------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
+posix.rename(path1, path2)+ :: |
|
|
+fs.rename(path1, path2)+ :: |
|
|
See rename(2). |
|
|
See rename(2). |
|
|
- on success: no parameters. |
|
|
- on success: no parameters. |
|
|
- on error: no parameters. |
|
|
- on error: no parameters. |
|
|
|
|
|
|
|
|
+posix.truncate(fd, len)+ :: |
|
|
+fs.truncate(fd, len)+ :: |
|
|
See ftruncate(2). |
|
|
See ftruncate(2). |
|
|
- on success: no parameters. |
|
|
- on success: no parameters. |
|
|
- on error: no parameters. |
|
|
- on error: no parameters. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+posix.stat(path)+ :: |
|
|
+fs.stat(path)+ :: |
|
|
See stat(2). |
|
|
See stat(2). |
|
|
- on success: Returns +posix.Stats+ object. It looks like this: |
|
|
- on success: Returns +fs.Stats+ object. It looks like this: |
|
|
+ |
|
|
+ |
|
|
------------------------------------------------------------------------------ |
|
|
------------------------------------------------------------------------------ |
|
|
{ dev: 2049, ino: 305352, mode: 16877, nlink: 12, uid: 1000, gid: 1000, |
|
|
{ dev: 2049, ino: 305352, mode: 16877, nlink: 12, uid: 1000, gid: 1000, |
|
@ -676,49 +676,49 @@ See stat(2). |
|
|
"2009-06-29T11:11:40Z" }+ |
|
|
"2009-06-29T11:11:40Z" }+ |
|
|
------------------------------------------------------------------------------ |
|
|
------------------------------------------------------------------------------ |
|
|
+ |
|
|
+ |
|
|
See the +posix.Stats+ section below for more information. |
|
|
See the +fs.Stats+ section below for more information. |
|
|
|
|
|
|
|
|
- on error: no parameters. |
|
|
- on error: no parameters. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+posix.unlink(path)+ :: |
|
|
+fs.unlink(path)+ :: |
|
|
See unlink(2) |
|
|
See unlink(2) |
|
|
- on success: no parameters. |
|
|
- on success: no parameters. |
|
|
- on error: no parameters. |
|
|
- on error: no parameters. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+posix.rmdir(path)+ :: |
|
|
+fs.rmdir(path)+ :: |
|
|
See rmdir(2) |
|
|
See rmdir(2) |
|
|
- on success: no parameters. |
|
|
- on success: no parameters. |
|
|
- on error: no parameters. |
|
|
- on error: no parameters. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+posix.mkdir(path, mode)+ :: |
|
|
+fs.mkdir(path, mode)+ :: |
|
|
See mkdir(2) |
|
|
See mkdir(2) |
|
|
- on success: no parameters. |
|
|
- on success: no parameters. |
|
|
- on error: no parameters. |
|
|
- on error: no parameters. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+posix.readdir(path)+ :: |
|
|
+fs.readdir(path)+ :: |
|
|
Reads the contents of a directory. |
|
|
Reads the contents of a directory. |
|
|
- on success: One argument, an array containing the names (strings) of the |
|
|
- on success: One argument, an array containing the names (strings) of the |
|
|
files in the directory (excluding "." and ".."). |
|
|
files in the directory (excluding "." and ".."). |
|
|
- on error: no parameters. |
|
|
- on error: no parameters. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+posix.close(fd)+ :: |
|
|
+fs.close(fd)+ :: |
|
|
See close(2) |
|
|
See close(2) |
|
|
- on success: no parameters. |
|
|
- on success: no parameters. |
|
|
- on error: no parameters. |
|
|
- on error: no parameters. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+posix.open(path, flags, mode)+:: |
|
|
+fs.open(path, flags, mode)+:: |
|
|
See open(2). The constants like +O_CREAT+ are defined at +process.O_CREAT+. |
|
|
See open(2). The constants like +O_CREAT+ are defined at +process.O_CREAT+. |
|
|
- on success: +fd+ is given as the parameter. |
|
|
- on success: +fd+ is given as the parameter. |
|
|
- on error: no parameters. |
|
|
- on error: no parameters. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+posix.write(fd, data, position, encoding)+:: |
|
|
+fs.write(fd, data, position, encoding)+:: |
|
|
Write data to the file specified by +fd+. +position+ refers to the offset |
|
|
Write data to the file specified by +fd+. +position+ refers to the offset |
|
|
from the beginning of the file where this data should be written. If |
|
|
from the beginning of the file where this data should be written. If |
|
|
+position+ is +null+, the data will be written at the current position. |
|
|
+position+ is +null+, the data will be written at the current position. |
|
@ -726,7 +726,7 @@ See the +posix.Stats+ section below for more information. |
|
|
- on success: returns an integer +written+ which specifies how many _bytes_ were written. |
|
|
- on success: returns an integer +written+ which specifies how many _bytes_ were written. |
|
|
- on error: no parameters. |
|
|
- on error: no parameters. |
|
|
|
|
|
|
|
|
+posix.read(fd, length, position, encoding)+:: |
|
|
+fs.read(fd, length, position, encoding)+:: |
|
|
Read data from the file specified by +fd+. |
|
|
Read data from the file specified by +fd+. |
|
|
+ |
|
|
+ |
|
|
+length+ is an integer specifying the number of |
|
|
+length+ is an integer specifying the number of |
|
@ -738,11 +738,11 @@ See the +posix.Stats+ section below for more information. |
|
|
- on success: returns +data, bytes_read+, what was read from the file. |
|
|
- on success: returns +data, bytes_read+, what was read from the file. |
|
|
- on error: no parameters. |
|
|
- on error: no parameters. |
|
|
|
|
|
|
|
|
+posix.cat(filename, encoding="utf8")+:: |
|
|
+fs.cat(filename, encoding="utf8")+:: |
|
|
Outputs the entire contents of a file. Example: |
|
|
Outputs the entire contents of a file. Example: |
|
|
+ |
|
|
+ |
|
|
-------------------------------- |
|
|
-------------------------------- |
|
|
posix.cat("/etc/passwd").addCallback(function (content) { |
|
|
fs.cat("/etc/passwd").addCallback(function (content) { |
|
|
sys.puts(content); |
|
|
sys.puts(content); |
|
|
}); |
|
|
}); |
|
|
-------------------------------- |
|
|
-------------------------------- |
|
@ -750,9 +750,9 @@ posix.cat("/etc/passwd").addCallback(function (content) { |
|
|
- on success: returns +data+, what was read from the file. |
|
|
- on success: returns +data+, what was read from the file. |
|
|
- on error: no parameters. |
|
|
- on error: no parameters. |
|
|
|
|
|
|
|
|
==== +posix.Stats+ |
|
|
==== +fs.Stats+ |
|
|
|
|
|
|
|
|
Objects returned from +posix.stat()+ are of this type. |
|
|
Objects returned from +fs.stat()+ are of this type. |
|
|
|
|
|
|
|
|
+stats.isFile()+:: |
|
|
+stats.isFile()+:: |
|
|
|
|
|
|
|
|