-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added examples to use parse. Updated readme.
- Loading branch information
djiao
committed
Feb 14, 2015
1 parent
6f4f232
commit 6f62fbc
Showing
6 changed files
with
214 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/test | ||
/samples | ||
.travis.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
// require should | ||
// npm install should -g | ||
|
||
// run this in the marc4js directory | ||
// node samples/parse_callback.js | ||
|
||
var marc4js = require('marc4js'); | ||
var fs = require('fs'); | ||
var should = require('should'); | ||
|
||
fs.readFile('samples/PGA-other-2.mrc', function(err, data) { | ||
marc4js.parse(data, {}, function(err, records) { | ||
records.length.should.eql(159); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
// require should | ||
// npm install should -g | ||
|
||
// run this in the marc4js directory | ||
// node samples/parse_pipe.js | ||
|
||
var marc4js = require('marc4js'); | ||
var fs = require('fs'); | ||
var should = require('should'); | ||
|
||
var parser = marc4js.parse(); | ||
var stringifier = marc4js.stringify(); | ||
|
||
var records = []; | ||
parser.on('data', function (record) { | ||
records.push(record); | ||
}); | ||
|
||
parser.on('error', function (error) { | ||
console.log("error: ", error); | ||
}); | ||
|
||
parser.on('end', function () { | ||
records.length.should.eql(159); | ||
}); | ||
|
||
fs.createReadStream('samples/PGA-other-2.mrc').pipe(parser).pipe(stringifier).pipe(process.stdout); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
// require should | ||
// npm install should -g | ||
|
||
// run this in the marc4js directory | ||
// node samples/parse_stream.js | ||
|
||
var marc4js = require('marc4js'); | ||
var fs = require('fs'); | ||
var should = require('should'); | ||
|
||
var parser = marc4js.parse(); | ||
var records = []; | ||
fs.readFile('samples/PGA-other-2.mrc', function(err, data) { | ||
parser.on('data', function (record) { | ||
records.push(record); | ||
}); | ||
|
||
parser.on('error', function (error) { | ||
console.log("error: ", error); | ||
}); | ||
|
||
parser.on('end', function () { | ||
records.length.should.eql(159); | ||
}); | ||
|
||
parser.write(data.toString()); | ||
parser.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
// require should | ||
// npm install should -g | ||
|
||
// run this in the marc4js directory | ||
// node samples/parse_stream_pipe.js | ||
|
||
var marc4js = require('marc4js'); | ||
var fs = require('fs'); | ||
var should = require('should'); | ||
|
||
var parser = marc4js.parse(); | ||
|
||
var records = []; | ||
parser.on('data', function (record) { | ||
records.push(record); | ||
}); | ||
|
||
parser.on('error', function (error) { | ||
console.log("error: ", error); | ||
}); | ||
|
||
parser.on('end', function () { | ||
records.length.should.eql(159); | ||
}); | ||
|
||
fs.createReadStream('samples/PGA-other-2.mrc').pipe(parser); |