Permalink
Browse files

Hurray it works

  • Loading branch information...
1 parent fccbe54 commit d65e67eec9cd27fbd46a79597edc5384bba066ab @thomaschaaf thomaschaaf committed Nov 18, 2012
Showing with 40 additions and 13 deletions.
  1. +15 −2 README.md
  2. +25 −11 lib/main.js
View
@@ -8,10 +8,23 @@ This is a Node.JS wrapper for [Zebra Crossing aka ZXing](http://code.google.com/
## Usage overview
+Install ZXing:
+```
+wget http://zxing.googlecode.com/files/ZXing-2.1.zip
+unzip ZXing-2.1
+cd zxing-2.1
+ant -f core/build.xml
+ant -f javase/build.xml
+```
+
```javascript
-var qrdecoder = require('node-zxing');
+var qrdecoder = require('./node-zxing')({ZXingLocation: "/opt/zxing-2.1/"});
var path = "./a.jpg";
-qrdecode.decode(a);
+qrdecoder.decode(path,
+ function(err, out) {
+ console.log(err,out);
+ }
+);
```
## TODO
View
@@ -3,9 +3,11 @@
var exec = require('child_process').exec;
-module.exports = function (ZXingLocation) {
- if(ZXingLocation == null) {
- ZXingLocation = "./"
+module.exports = function (options) {
+ var defaults = options || {};
+
+ if(defaults.ZXingLocation == null) {
+ defaults.ZXingLocation = "";
}
var commandLineOptions = " ";
@@ -14,16 +16,28 @@ module.exports = function (ZXingLocation) {
}
return {
decode: function(path, cb) {
- qrcode = "";
- exec('java -cp '+ZXingLocation+'/javase/javase.jar:'+ZXingLocation+'/core/core.jar com.google.zxing.client.j2se.CommandLineRunner'+commandLineOptions+''+path, function(err, stdout, strerr){
- if(err !== null) {
+ exec('java -cp '+defaults.ZXingLocation+'/javase/javase.jar:'+defaults.ZXingLocation+'/core/core.jar com.google.zxing.client.j2se.CommandLineRunner'+commandLineOptions+''+path,
+ function(err, stdout, stderr){
+ var qrcode = "";
+ var errorCache = null;
console.log(err, stdout, stderr);
- cb(error, '');
- } else {
- console.log(stdout);
- cb(null, stdout);
+ if(err !== null) {
+ console.log(err, stdout, stderr);
+ errorCache = err;
+ } else {
+ var lines = stdout.split("\n");
+
+ for(var i in lines) {
+ if(lines[i] == 'Raw result:') {
+ qrcode = lines[parseInt(i)+1];
+ break;
+ }
+ }
+
+ }
+ cb(errorCache, qrcode);
}
- });
+ );
}
};
}

0 comments on commit d65e67e

Please sign in to comment.