From 676e210fc451a8da21074b7856729f9957af5d01 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Fri, 9 Nov 2012 05:20:15 -0500 Subject: [PATCH] Fixes issue #32 --- lib/wrench.js | 4 ++++ readme.md | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/wrench.js b/lib/wrench.js index c7d72e5..247874a 100644 --- a/lib/wrench.js +++ b/lib/wrench.js @@ -369,6 +369,10 @@ exports.LineReader = function(filename, bufferSize) { }; exports.LineReader.prototype = { + close: function() { + return fs.closeSync(this.fd); + }, + getBufferAndSetCurrentPosition: function(position) { var res = fs.readSync(this.fd, this.bufferSize, position, "ascii"); diff --git a/readme.md b/readme.md index 393e3da..243c0da 100644 --- a/readme.md +++ b/readme.md @@ -45,6 +45,10 @@ var f = new wrench.LineReader('x.txt'); while(f.hasNextLine()) { util.puts(x.getNextLine()); } + +// Note: You will need to close that above line reader at some point, otherwise +// you will run into a "too many open files" error. f.close() or fs.closeSync(f.fd) are +// your friends, as only you know when it is safe to close. ``` ### Asynchronous operations @@ -54,7 +58,6 @@ var files = []; wrench.readdirRecursive('my_directory_name', function(error, curFiles) { // curFiles is what you want }); - ``` Questions, comments? Hit me up. (ryan [at] venodesigns.net | http://twitter.com/ryanmcgrath)