2018-04-14 23:10:26 +03:00
|
|
|
'use strict';
|
|
|
|
|
2018-07-23 01:25:36 +03:00
|
|
|
import { arrayify } from '../utils/bytes';
|
2018-04-14 23:10:26 +03:00
|
|
|
|
|
|
|
module.exports = {
|
2018-06-23 03:30:50 +03:00
|
|
|
decode: function(textData: string): Uint8Array {
|
2018-04-14 23:10:26 +03:00
|
|
|
textData = atob(textData);
|
|
|
|
var data = [];
|
|
|
|
for (var i = 0; i < textData.length; i++) {
|
|
|
|
data.push(textData.charCodeAt(i));
|
|
|
|
}
|
2018-06-14 09:25:56 +03:00
|
|
|
return arrayify(data);
|
2018-04-14 23:10:26 +03:00
|
|
|
},
|
2018-06-23 03:30:50 +03:00
|
|
|
encode: function(data: Uint8Array): string {
|
2018-06-14 09:25:56 +03:00
|
|
|
data = arrayify(data);
|
2018-04-14 23:10:26 +03:00
|
|
|
var textData = '';
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
|
textData += String.fromCharCode(data[i]);
|
|
|
|
}
|
|
|
|
return btoa(textData);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|