recordSource.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. class TransCoding {
  2. constructor(params) {
  3. this.params = params
  4. this.toBase64Table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  5. this.base64Pad = '='
  6. }
  7. toBase64() {
  8. let result = ''
  9. let length = this.params.length
  10. let i
  11. for (i = 0; i < (length - 2); i += 3) {
  12. result += this.toBase64Table[this.params.charCodeAt(i) >> 2];
  13. result += this.toBase64Table[((this.params.charCodeAt(i) & 0x03) << 4) + (this.params.charCodeAt(i + 1) >> 4)];
  14. result += this.toBase64Table[((this.params.charCodeAt(i + 1) & 0x0f) << 2) + (this.params.charCodeAt(i + 2) >> 6)];
  15. result += this.toBase64Table[this.params.charCodeAt(i + 2) & 0x3f];
  16. }
  17. if (length % 3) {
  18. i = length - (length % 3);
  19. result += this.toBase64Table[this.params.charCodeAt(i) >> 2];
  20. if ((length % 3) == 2) {
  21. result += this.toBase64Table[((this.params.charCodeAt(i) & 0x03) << 4) + (this.params.charCodeAt(i + 1) >> 4)];
  22. result += this.toBase64Table[(this.params.charCodeAt(i + 1) & 0x0f) << 2];
  23. result += this.base64Pad;
  24. } else {
  25. result += this.toBase64Table[(this.params.charCodeAt(i) & 0x03) << 4];
  26. result += this.base64Pad + this.base64Pad;
  27. }
  28. }
  29. return result;
  30. }
  31. encode() {
  32. return encodeURIComponent(this.toBase64())
  33. }
  34. }
  35. function recordSource(app, params) {
  36. let fromSource = app.globalData.fromSource
  37. let currentSource = new TransCoding(params).encode()
  38. app.setFromSource(currentSource)
  39. return fromSource
  40. }
  41. export default recordSource