Skip to content

Commit

Permalink
Merge pull request #37 from RReverser/master
Browse files Browse the repository at this point in the history
Untar demo works in IE7 again
  • Loading branch information
vjeux committed Apr 5, 2013
2 parents 4ec8e24 + dc52b25 commit 062b5dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 4 additions & 2 deletions demo/untar/untar.html
@@ -1,8 +1,10 @@
<script src="../../jquery/jquery-1.4.4-binary-ajax.js"></script> <script src="json.js"></script>
<script src="../../jquery/jquery-1.7.1-binary-ajax.js"></script>
<script src="../../src/jdataview.js"></script> <script src="../../src/jdataview.js"></script>


<style> <style>
textarea { width: 80%; height: 300px; } textarea { width: 80%; height: 300px; }
pre { word-wrap: break-word; }
</style> </style>
<p>Content of the file <a href="jquery.tar">jquery.tar</a></p> <p>Content of the file <a href="jquery.tar">jquery.tar</a></p>


Expand Down Expand Up @@ -60,6 +62,6 @@
} }


// Download the file // Download the file
$.get('jquery.tar', tar, 'binary'); $.get('jquery.tar', tar);


</script> </script>
16 changes: 10 additions & 6 deletions src/jdataview.js
Expand Up @@ -326,13 +326,19 @@ var jDataView = function (buffer, byteOffset, byteLength, littleEndian) {
} }
}; };


function getCharCodes(string) {
var codes = new Array(string.length);
for (var i = 0, length = string.length; i < length; i++) {
codes[i] = string.charCodeAt(i) & 0xff;
}
return codes;
}

// mostly internal function for wrapping any supported input (String or Array-like) to best suitable buffer format // mostly internal function for wrapping any supported input (String or Array-like) to best suitable buffer format
jDataView.wrapBuffer = function (buffer) { jDataView.wrapBuffer = function (buffer) {
switch (typeof buffer) { switch (typeof buffer) {
case 'string': case 'string':
buffer = Array.prototype.map.call(buffer, function (char) { buffer = getCharCodes(buffer);
return char.charCodeAt(0) & 0xff;
});
break; break;


case 'number': case 'number':
Expand Down Expand Up @@ -481,9 +487,7 @@ jDataView.prototype = {
}, },


setString: function (byteOffset, subString) { setString: function (byteOffset, subString) {
this.setBytes(byteOffset, Array.prototype.map.call(subString, function (char) { this.setBytes(byteOffset, getCharCodes(subString), true);
return char.charCodeAt(0) & 0xff;
}), true);
}, },


writeString: function (subString) { writeString: function (subString) {
Expand Down

0 comments on commit 062b5dd

Please sign in to comment.