Skip to content

Commit

Permalink
Fix Enamdict downloader and update dict file.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeresig committed Nov 12, 2016
1 parent f9f82b2 commit a95a2b8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 36 deletions.
33 changes: 2 additions & 31 deletions download-enamdict.js
@@ -1,6 +1,6 @@
/**
* Utility for downloading the latest ENAMDICT, converting it to the right
* encoding, re-formatting it, and saving as a compressed file.
* encoding, re-formatting it, and outputting it to STDOUT.
*/
var enamdict = require("./enamdict");
var fs = require("fs");
Expand All @@ -12,15 +12,6 @@ var Iconv = require("iconv").Iconv;
// The default URL where the enamdict file is located
var enamdictURL = "http://ftp.monash.edu.au/pub/nihongo/enamdict.gz";

try {
fs.statSync(enamdict.enamdictFile);
process.exit(0);
} catch(e) {
// If it doesn't exist then we need to download the dict
}

console.log("Downloading ENAMDICT...");

// Download the ENMADICT database
var stream = request(enamdictURL)
// Extract it...
Expand All @@ -30,28 +21,8 @@ var stream = request(enamdictURL)

// Load it into the enamdict module
enamdict.init(stream, function() {
console.log("Processing...");

// And then convert it to the desired file format
enamdict.process(function(err, data) {
console.log("Outputting...");

// Write out the result to a file!
// Stick the string into the stream.
var stream = new Stream();

stream.pipe = function(dest) {
dest.write(data);
return dest;
};

stream
// Make sure it's gzipped
.pipe(zlib.createGzip())
// Write it out to a file
.pipe(fs.createWriteStream(enamdict.enamdictFile))
.on("end", function() {
console.log("DONE");
});
return console.log(data);
});
});
Binary file modified enamdict.gz
Binary file not shown.
10 changes: 5 additions & 5 deletions package.json
@@ -1,11 +1,11 @@
{
"name": "enamdict",
"version": "0.1.4",
"version": "0.1.5",
"description": "Efficiently query ENAMDICT using Node.js.",
"main": "enamdict.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"install": "node download-enamdict.js"
"update": "node download-enamdict.js | gzip > enamdict.gz"
},
"repository": {
"type": "git",
Expand All @@ -24,8 +24,8 @@
"url": "https://github.com/jeresig/node-enamdict/issues"
},
"dependencies": {
"concat-stream": "~1.5.2",
"iconv": "^2.1.11",
"request": "~2.75.0"
"concat-stream": "1.5.2",
"iconv": "2.2.1",
"request": "2.78.0"
}
}

0 comments on commit a95a2b8

Please sign in to comment.