Permalink
Browse files

updated readme

  • Loading branch information...
1 parent 31ef7d2 commit e617724bb41b35983804de1f70e3336c82a86881 Gabriel Llamas committed Aug 5, 2012
Showing with 39 additions and 1 deletion.
  1. +39 −1 README.md
View
40 README.md
@@ -5,14 +5,52 @@ Node BufferedReader
#### Fully configurable buffered reader for node.js ####
-[Availability](#availability) | [Compatibility](#compatibility) | [Documentation](#documentation)
+[Show me!](#showme) | [Availability](#availability) | [Compatibility](#compatibility) | [Documentation](#documentation)
Version: 0.2.6
When you need to read a file you typically read a chunk of bytes called "buffer" to avoid multiple calls to the underlying I/O layer, so instead of reading directly from the disk, you read from the previous filled buffer. Doing this you win performance.
This library allows you to read files using internal buffers, so you don't have to worry about them. In addition, you can read a text file line by line.
+<a name="showme"></a>
+#### Show me! [](#start) ####
+
+```javascript
+var BufferedReader = require ("../build/buffered-reader");
+
+var offset;
+
+new BufferedReader ("file", { encoding: "utf8" })
+ .on ("error", function (error){
+ console.log (error);
+ })
+ .on ("line", function (line, byteOffset){
+ if (line === "Phasellus ultrices ligula sed odio ultricies egestas."){
+ offset = byteOffset;
+ this.interrupt ();
+ }
+ })
+ .on ("end", function (){
+ this.seek (offset, function (error){
+ if (error) return console.log (error);
+
+ this.readBytes (9, function (error, bytes, bytesRead){
+ if (error) return console.log (error);
+
+ console.log (bytes.toString ());
+
+ this.close (function (error){
+ if (error) console.log (error);
+ });
+ });
+ })
+ })
+ .read ();
+```
+
+***
+
<a name="availability"></a>
#### Availability [](#start) ####

0 comments on commit e617724

Please sign in to comment.