-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update go packages * Cleanup go modules * PR improvements
- Loading branch information
Showing
9 changed files
with
294 additions
and
1,642 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
let chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; | ||
|
||
// Use a lookup table to find the index. | ||
let lookup = new Uint8Array(256); | ||
for (let i = 0; i < chars.length; i++) { | ||
lookup[chars.charCodeAt(i)] = i; | ||
} | ||
|
||
export function bufferDecode(base64string: string) { | ||
const bufferLength = base64string.length * 0.75; | ||
const len = base64string.length | ||
let p = 0; | ||
let encoded1: number; | ||
let encoded2: number; | ||
let encoded3: number; | ||
let encoded4: number; | ||
|
||
let bytes = new Uint8Array(bufferLength); | ||
|
||
for (let i = 0; i < len; i+=4) { | ||
encoded1 = lookup[base64string.charCodeAt(i)]; | ||
encoded2 = lookup[base64string.charCodeAt(i+1)]; | ||
encoded3 = lookup[base64string.charCodeAt(i+2)]; | ||
encoded4 = lookup[base64string.charCodeAt(i+3)]; | ||
|
||
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4); | ||
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2); | ||
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63); | ||
} | ||
|
||
return bytes.buffer | ||
} | ||
|
||
export function bufferEncode(arraybuffer: any) { | ||
const bytes = new Uint8Array(arraybuffer); | ||
const len = bytes.length; | ||
let base64url = ''; | ||
|
||
for (let i = 0; i < len; i+=3) { | ||
base64url += chars[bytes[i] >> 2]; | ||
base64url += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)]; | ||
base64url += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)]; | ||
base64url += chars[bytes[i + 2] & 63]; | ||
} | ||
|
||
if ((len % 3) === 2) { | ||
base64url = base64url.substring(0, base64url.length - 1); | ||
} else if (len % 3 === 1) { | ||
base64url = base64url.substring(0, base64url.length - 2); | ||
} | ||
|
||
return base64url; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.