From b82ef28d9d27df56fa3b7c00c8c4209c227ae68c Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Fri, 12 Feb 2010 01:04:14 -0800 Subject: Rename 'posix' module to 'fs' --- doc/api.txt | 56 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'doc/api.txt') diff --git a/doc/api.txt b/doc/api.txt index 33d4d6718..98fe9a4b7 100644 --- a/doc/api.txt +++ b/doc/api.txt @@ -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)+:: 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 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 (+events.Promise+). Example of deleting a file: ------------------------------------------------------------------------------ -var posix = require("posix"), - sys = require("sys"); +var fs = require("fs"), + sys = require("sys"); -var promise = posix.unlink("/tmp/hello"); +var promise = fs.unlink("/tmp/hello"); promise.addCallback(function () { 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 ------------------------------------------------------------------------------ -posix.rename("/tmp/hello", "/tmp/world"); -posix.stat("/tmp/world").addCallback(function (stats) { +fs.rename("/tmp/hello", "/tmp/world"); +fs.stat("/tmp/world").addCallback(function (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. ------------------------------------------------------------------------------ -posix.rename("/tmp/hello", "/tmp/world").addCallback(function () { - posix.stat("/tmp/world").addCallback(function (stats) { +fs.rename("/tmp/hello", "/tmp/world").addCallback(function () { + fs.stat("/tmp/world").addCallback(function (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: ------------------------------------------------------------------------------ -posix.rename("/tmp/hello", "/tmp/world").wait(); -var stats = posix.stat("/tmp/world").wait(); +fs.rename("/tmp/hello", "/tmp/world").wait(); +var stats = fs.stat("/tmp/world").wait(); sys.puts("stats: " + JSON.stringify(stats)); ------------------------------------------------------------------------------ -+posix.rename(path1, path2)+ :: ++fs.rename(path1, path2)+ :: See rename(2). - on success: no parameters. - on error: no parameters. -+posix.truncate(fd, len)+ :: ++fs.truncate(fd, len)+ :: See ftruncate(2). - on success: no parameters. - on error: no parameters. -+posix.stat(path)+ :: ++fs.stat(path)+ :: 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, @@ -676,49 +676,49 @@ See stat(2). "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. -+posix.unlink(path)+ :: ++fs.unlink(path)+ :: See unlink(2) - on success: no parameters. - on error: no parameters. -+posix.rmdir(path)+ :: ++fs.rmdir(path)+ :: See rmdir(2) - on success: no parameters. - on error: no parameters. -+posix.mkdir(path, mode)+ :: ++fs.mkdir(path, mode)+ :: See mkdir(2) - on success: no parameters. - on error: no parameters. -+posix.readdir(path)+ :: ++fs.readdir(path)+ :: Reads the contents of a directory. - on success: One argument, an array containing the names (strings) of the files in the directory (excluding "." and ".."). - on error: no parameters. -+posix.close(fd)+ :: ++fs.close(fd)+ :: See close(2) - on success: 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+. - on success: +fd+ is given as the parameter. - 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 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. @@ -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 error: no parameters. -+posix.read(fd, length, position, encoding)+:: ++fs.read(fd, length, position, encoding)+:: Read data from the file specified by +fd+. + +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 error: no parameters. -+posix.cat(filename, encoding="utf8")+:: ++fs.cat(filename, encoding="utf8")+:: 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); }); -------------------------------- @@ -750,9 +750,9 @@ posix.cat("/etc/passwd").addCallback(function (content) { - on success: returns +data+, what was read from the file. - 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()+:: -- cgit v1.2.1