Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for binary files #42

Merged
merged 12 commits into from
Oct 23, 2018
5 changes: 4 additions & 1 deletion lib/CachedSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ class CachedSource extends Source {

size() {
if(typeof this._cachedSize !== "undefined") return this._cachedSize;
if(typeof this._cachedSource !== "undefined")
if(typeof this._cachedSource !== "undefined") {
if(this._cachedSource instanceof ArrayBuffer)
return this._cachedSize = this._cachedSource.byteLength;
return this._cachedSize = this._cachedSource.length;
}
return this._cachedSize = this._source.size();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ReplaceSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class ReplaceSource extends Source {
// Recurse with remainder of the string as there may be multiple replaces within a single node
node = node.substr(splitPosition);
position += splitPosition;
} while (true);
} while(true);
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/Source.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Source {
}

size() {
if(this.source() instanceof ArrayBuffer) return this.source().byteLength;
return this.source().length;
}

Expand Down
5 changes: 5 additions & 0 deletions test/OriginalSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ describe("OriginalSource", function() {

resultMap.mappings.should.be.eql("AAAA;AACA;AACA");
});

it("should return the correct size for binary files", function() {
var source = new OriginalSource(new ArrayBuffer(256), "file.wasm");
source.size().should.be.eql(256);
});
});