From: Ryan Date: Fri, 31 Jul 2009 17:56:53 +0000 (+0200) Subject: Add examples of reading a file to documentation. X-Git-Tag: v0.1.2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c745383b31a30ada8db79c653e9c3bf7d062cbe1;p=platform%2Fupstream%2Fnodejs.git Add examples of reading a file to documentation. --- diff --git a/website/api.txt b/website/api.txt index fdd5649..90c0d1d 100644 --- a/website/api.txt +++ b/website/api.txt @@ -482,6 +482,19 @@ or +node.RAW+. - on success: returns +data, bytes_read+, what was read from the file. - on error: no parameters. ++node.fs.cat(filename, encoding)+:: + +Outputs the entire contents of a file. Example: ++ +-------------------------------- +node.fs.cat("/etc/passwd", "utf8").addCallback(function (content) { + puts(content); +}); +-------------------------------- ++ +- on success: returns +data+, what was read from the file. +- on error: no parameters. + ==== +node.fs.File+ @@ -498,6 +511,18 @@ file.write("world"); file.close(); ---------------------------------------- +Here is an example of reading the first 10 bytes from +/etc/passwd+ and +outputting it to +stdout+. + +---------------------------------------- +var file = new node.fs.File({encoding: "utf8"}); +file.open("/etc/passwd", "r"); +file.read(10).addCallback(function (chunk) { + puts(chunk); +}); +file.close(); +---------------------------------------- + [cols="1,2,10",options="header"] |========================================================= |Event |Parameters | Notes