Skip to content

Commit

Permalink
Added early return option to fetchAll (to retrieve a single box).
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjoerd Tieleman committed Jun 2, 2015
1 parent 612db4d commit 0b99fac
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
11 changes: 6 additions & 5 deletions dist/iso_boxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,13 @@ var ISOFile = function(arrayBuffer) {
}

ISOFile.prototype.fetch = function(type) {
var result = this.fetchAll(type);
var result = this.fetchAll(type, true);
return (result.length ? result[0] : null);
}

ISOFile.prototype.fetchAll = function(type) {
ISOFile.prototype.fetchAll = function(type, returnEarly) {
var result = [];
ISOFile._sweep.call(this, type, result);
ISOFile._sweep.call(this, type, result, returnEarly);
return result;
}

Expand All @@ -426,9 +426,10 @@ ISOFile.prototype.parse = function() {
return this;
}

ISOFile._sweep = function(type, result) {
ISOFile._sweep = function(type, result, returnEarly) {
if (this.type && this.type == type) result.push(this);
for (var box in this.boxes) {
ISOFile._sweep.call(this.boxes[box], type, result);
if (result.length && returnEarly) return;
ISOFile._sweep.call(this.boxes[box], type, result, returnEarly);
}
}
2 changes: 1 addition & 1 deletion dist/iso_boxer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0b99fac

Please sign in to comment.