js-rpc2 2.3.1 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/lib.js +17 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-rpc2",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "description": "js web websocket http rpc",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/lib.js CHANGED
@@ -774,10 +774,10 @@ export function _testCreateRpcClientHttp(param) {
774
774
  method: 'POST',
775
775
  signal: param.signal,
776
776
  // @ts-ignore
777
- duplex:'half',
777
+ duplex: 'half',
778
778
  body: new ReadableStream({
779
- async pull(controller){
780
- controller.enqueue(chunk.slice(0,10))
779
+ async pull(controller) {
780
+ controller.enqueue(chunk.slice(0, 10))
781
781
  await sleep(1000)
782
782
  controller.enqueue(chunk.slice(10))
783
783
  controller.close()
@@ -873,25 +873,28 @@ export function createRpcClientMessagePort(param) {
873
873
 
874
874
  /**
875
875
  * @param {string} text
876
- * @returns
877
876
  */
878
877
  export function base64decode(text) {
879
- const _tidyB64 = (/** @type {string} */ s) => s.replace(/[^A-Za-z0-9\+\/]/g, '')
880
- const _unURI = (/** @type {string} */ a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == '-' ? '+' : '/'))
881
- text = _unURI(text)
882
- return new Uint8Array(globalThis.atob(text).split('').map(c => c.charCodeAt(0)))
878
+ const binaryString = atob(text)
879
+ const len = binaryString.length
880
+ const bytes = new Uint8Array(len)
881
+ for (let i = 0; i < len; i++) {
882
+ bytes[i] = binaryString.charCodeAt(i)
883
+ }
884
+ return bytes
883
885
  }
884
886
 
885
887
  /**
886
888
  * @param {Uint8Array<ArrayBuffer>} buffer
887
- * @returns
888
889
  */
889
- export function base64encode(buffer, urlsafe = false) {
890
- let b64 = globalThis.btoa(String.fromCharCode(...new Uint8Array(buffer)))
891
- if (urlsafe) {
892
- b64 = b64.replace(/=/g, '').replace(/[+\/]/g, (m0) => m0 == '+' ? '-' : '_')
890
+ export function base64encode(buffer) {
891
+ const CHUNK_SZ = 0x8000
892
+ const chars = []
893
+ for (let i = 0; i < buffer.length; i += CHUNK_SZ) {
894
+ const chunk = buffer.subarray(i, i + CHUNK_SZ)
895
+ chars.push(String.fromCharCode.apply(null, chunk))
893
896
  }
894
- return b64
897
+ return btoa(chars.join(''))
895
898
  }
896
899
 
897
900
  /**