Skip to content

Commit

Permalink
Removed caching from readAsString and readAsJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
Qvazar committed Sep 18, 2015
1 parent bc1f84e commit b225b2a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 36 deletions.
34 changes: 15 additions & 19 deletions build/dev/untar.js

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

2 changes: 1 addition & 1 deletion build/dist/untar.js

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

28 changes: 12 additions & 16 deletions src/untar.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,25 @@ var decoratedFileProps = {
},
readAsString: {
value: function() {
if (this._string) {
return this._string;
} else {
var buffer = this.buffer;
var charCount = buffer.byteLength;
var charSize = 1;
var byteCount = charCount * charSize;
var bufferView = new DataView(buffer);
var buffer = this.buffer;
var charCount = buffer.byteLength;
var charSize = 1;
var byteCount = charCount * charSize;
var bufferView = new DataView(buffer);

var charCodes = [];
var charCodes = [];

for (var i = 0; i < charCount; ++i) {
var charCode = bufferView.getUint8(i * charSize, true);
charCodes.push(charCode);
}

return (this._string = String.fromCharCode.apply(null, charCodes));
for (var i = 0; i < charCount; ++i) {
var charCode = bufferView.getUint8(i * charSize, true);
charCodes.push(charCode);
}

return (this._string = String.fromCharCode.apply(null, charCodes));
}
},
readAsJSON: {
value: function() {
return this._json || (this._json = JSON.parse(this.readAsString()));
return JSON.parse(this.readAsString());
}
}
};
Expand Down

0 comments on commit b225b2a

Please sign in to comment.