1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- class TransCoding {
- constructor(params) {
- this.params = params
- this.toBase64Table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
- this.base64Pad = '='
- }
- toBase64() {
- let result = ''
- let length = this.params.length
- let i
- for (i = 0; i < (length - 2); i += 3) {
- result += this.toBase64Table[this.params.charCodeAt(i) >> 2];
- result += this.toBase64Table[((this.params.charCodeAt(i) & 0x03) << 4) + (this.params.charCodeAt(i + 1) >> 4)];
- result += this.toBase64Table[((this.params.charCodeAt(i + 1) & 0x0f) << 2) + (this.params.charCodeAt(i + 2) >> 6)];
- result += this.toBase64Table[this.params.charCodeAt(i + 2) & 0x3f];
- }
- if (length % 3) {
- i = length - (length % 3);
- result += this.toBase64Table[this.params.charCodeAt(i) >> 2];
- if ((length % 3) == 2) {
- result += this.toBase64Table[((this.params.charCodeAt(i) & 0x03) << 4) + (this.params.charCodeAt(i + 1) >> 4)];
- result += this.toBase64Table[(this.params.charCodeAt(i + 1) & 0x0f) << 2];
- result += this.base64Pad;
- } else {
- result += this.toBase64Table[(this.params.charCodeAt(i) & 0x03) << 4];
- result += this.base64Pad + this.base64Pad;
- }
- }
- return result;
- }
- encode() {
- return encodeURIComponent(this.toBase64())
- }
- }
- function recordSource(app, params) {
- let fromSource = app.globalData.fromSource
- let currentSource = new TransCoding(params).encode()
- app.setFromSource(currentSource)
- return fromSource
- }
- export default recordSource
|