Skip to content

Commit c745383

Browse files
committed
Add examples of reading a file to documentation.
1 parent 4f46c47 commit c745383

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

website/api.txt

+25
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,19 @@ or +node.RAW+.
482482
- on success: returns +data, bytes_read+, what was read from the file.
483483
- on error: no parameters.
484484

485+
+node.fs.cat(filename, encoding)+::
486+
487+
Outputs the entire contents of a file. Example:
488+
+
489+
--------------------------------
490+
node.fs.cat("/etc/passwd", "utf8").addCallback(function (content) {
491+
puts(content);
492+
});
493+
--------------------------------
494+
+
495+
- on success: returns +data+, what was read from the file.
496+
- on error: no parameters.
497+
485498

486499
==== +node.fs.File+
487500

@@ -498,6 +511,18 @@ file.write("world");
498511
file.close();
499512
----------------------------------------
500513

514+
Here is an example of reading the first 10 bytes from +/etc/passwd+ and
515+
outputting it to +stdout+.
516+
517+
----------------------------------------
518+
var file = new node.fs.File({encoding: "utf8"});
519+
file.open("/etc/passwd", "r");
520+
file.read(10).addCallback(function (chunk) {
521+
puts(chunk);
522+
});
523+
file.close();
524+
----------------------------------------
525+
501526
[cols="1,2,10",options="header"]
502527
|=========================================================
503528
|Event |Parameters | Notes

0 commit comments

Comments
 (0)