Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding a test to see if the source is an unreadable stream.

  • Loading branch information...
commit f3ad5a26be8025a8e784ec88b97823f6ba3c80c9 1 parent 66f7c7a
@Zoramite Zoramite authored
Showing with 20 additions and 0 deletions.
  1. +4 −0 lib/xml2object.js
  2. +16 −0 test/stream-test.js
View
4 lib/xml2object.js
@@ -27,6 +27,10 @@ var xml2object = module.exports = function(elements, source) {
},
set: function (val) {
if(val instanceof Stream) {
+ if(!val.readable) {
+ throw new Error('Source stream is not readable');
+ }
+
// Allowing for passing in a readable stream
self.inputStream = val;
} else if(typeof val === 'string') {
View
16 test/stream-test.js
@@ -48,3 +48,19 @@ exports.testSetter = function(test){
parser.start();
};
+
+exports.testSetterUnreadable = function(test){
+ test.expect(1);
+
+ var stream = fs.createReadStream(path.normalize(__dirname + '/fixture/input01.xml'));
+ var parser = new xml2object(['cat']);
+
+ // Make the stream non-readable by destroying
+ stream.destroy();
+
+ test.throws(function() {
+ parser.source = stream;
+ }, Error);
+
+ test.done();
+};
Please sign in to comment.
Something went wrong with that request. Please try again.