diff --git a/CREDITS.md b/CREDITS.md index 4bcb181..3d7bf16 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -17,3 +17,8 @@ * Andrew Kepert * Ydnar * Lostinet + + +## [String/ArrayBuffer conversion](http://updates.html5rocks.com/2012/06/How-to-convert-ArrayBuffer-to-and-from-String) + +* Renato Mangini diff --git a/manifest.json b/manifest.json index 50b32f1..a853aaf 100644 --- a/manifest.json +++ b/manifest.json @@ -7,6 +7,7 @@ "app": { "background": { "scripts": ["third-party/md5-min.js", + "third-party/ab-str.js", "lib/ns_client.js", "background.js" ] diff --git a/third-party/ab-str.js b/third-party/ab-str.js new file mode 100644 index 0000000..2bba23b --- /dev/null +++ b/third-party/ab-str.js @@ -0,0 +1,18 @@ +// +// Renato Mangini +// http://updates.html5rocks.com/2012/06/How-to-convert-ArrayBuffer-to-and-from-String +// http://stackoverflow.com/questions/6965107/converting-between-strings-and-arraybuffers +// + +function ab2str(buf) { + return String.fromCharCode.apply(null, new Uint16Array(buf)); +} + +function str2ab(str) { + var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char + var bufView = new Uint16Array(buf); + for (var i=0, strLen=str.length; i