Skip to content
Browse files

cleaned up some dangling file-handles

  • Loading branch information...
1 parent 5607d5e commit 12eb638bb747a3592a26a3c0618ccb520680fd0d @chrisumbel committed
View
6 .gitignore
@@ -4,4 +4,8 @@
classifier.json
node_modules
.*
-spec/test_data/wordnet/download/*
+io_spec/test_data/wordnet/download/*
+*.noun
+*.verb
+*.adj
+*.adv
View
82,144 io_spec/test_data/wordnet/download/data.noun
82,144 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
21,508 io_spec/test_data/wordnet/download/index.adj
21,508 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
4,510 io_spec/test_data/wordnet/download/index.adv
4,510 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
117,827 io_spec/test_data/wordnet/download/index.noun
117,827 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
11,558 io_spec/test_data/wordnet/download/index.verb
11,558 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
3 lib/natural/wordnet/data_file.js
@@ -26,8 +26,9 @@ var WordNetFile = require('./wordnet_file'),
function get(location, callback) {
var buff = new Buffer(4096);
- this.open(function(err, fd) {
+ this.open(function(err, fd, done) {
WordNetFile.appendLineChar(fd, location, 0, buff, function(line) {
+ done();
var data = line.split('| ');
var tokens = data[0].split(/\s+/);
var ptrs = [];
View
19 lib/natural/wordnet/index_file.js
@@ -63,7 +63,7 @@ function findAt(fd, size, pos, lastPos, adjustment, searchKey, callback) {
var tokens = line.split(/\s+/);
var key = tokens[0];
- if(key == searchKey) {
+ if(key == searchKey) {
callback({status: 'hit', key: key, 'line': line, tokens: tokens});
} else if(adjustment == 1) {
miss(callback);
@@ -80,20 +80,22 @@ function findAt(fd, size, pos, lastPos, adjustment, searchKey, callback) {
}
}
-function find(WordNetFile, searchKey, callback) {
- WordNetFile.open(function(err, fd) {
+function find(searchKey, callback) {
+ var indexFile = this;
+
+ indexFile.open(function(err, fd, done) {
if(err) {
console.log(err);
} else {
- var size = getFileSize(WordNetFile.filePath) - 1;
+ var size = getFileSize(indexFile.filePath) - 1;
var pos = Math.ceil(size / 2);
- findAt(fd, size, pos, null, pos, searchKey, callback);
+ findAt(fd, size, pos, null, pos, searchKey, function(result) { callback(result); done() });
}
- });
+ });
}
function lookupFromFile(word, callback) {
- find(this, word, function(record) {
+ this.find(word, function(record) {
var indexRecord = null;
if(record.status == 'hit') {
@@ -126,7 +128,8 @@ function lookup(word, callback) {
var IndexFile = function(dataDir, base, name) {
var indexFile = new WordNetFile(dataDir, base, 'index.' + name);
indexFile.lookupFromFile = lookupFromFile;
- indexFile.lookup = lookup;
+ indexFile.lookup = lookup;
+ indexFile.find = find;
return indexFile;
};
View
4 lib/natural/wordnet/wordnet_file.js
@@ -84,8 +84,8 @@ function open(callback) {
path.exists(filePath, function(exists) {
var _open = function(){
fs.open(filePath, 'r', null, function(err, fd) {
- callback(err, fd);
- });
+ callback(err, fd, function() {fs.close(fd)});
+ });
};
if(exists) {

0 comments on commit 12eb638

Please sign in to comment.
Something went wrong with that request. Please try again.