using Uint8Array instead of Uint16Array
This commit is contained in:
parent
a8a6df51ce
commit
8f25b4c862
1 changed files with 6 additions and 3 deletions
9
third-party/ab-str.js
vendored
9
third-party/ab-str.js
vendored
|
@ -3,14 +3,17 @@
|
|||
// http://updates.html5rocks.com/2012/06/How-to-convert-ArrayBuffer-to-and-from-String
|
||||
// http://stackoverflow.com/questions/6965107/converting-between-strings-and-arraybuffers
|
||||
//
|
||||
// Edited by Rodolphe Breard
|
||||
// - Using Uint8Array instead of Uint16Array
|
||||
//
|
||||
|
||||
function ab2str(buf) {
|
||||
return String.fromCharCode.apply(null, new Uint16Array(buf));
|
||||
return String.fromCharCode.apply(null, new Uint8Array(buf));
|
||||
}
|
||||
|
||||
function str2ab(str) {
|
||||
var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
|
||||
var bufView = new Uint16Array(buf);
|
||||
var buf = new ArrayBuffer(str.length);
|
||||
var bufView = new Uint8Array(buf);
|
||||
for (var i=0, strLen=str.length; i<strLen; i++) {
|
||||
bufView[i] = str.charCodeAt(i);
|
||||
}
|
||||
|
|
Reference in a new issue