ts-proto 1.121.3 → 1.121.4
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.
- package/CHANGELOG.md +7 -0
- package/build/main.js +18 -12
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.121.4](https://github.com/stephenh/ts-proto/compare/v1.121.3...v1.121.4) (2022-08-07)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Performance Improvements
|
|
5
|
+
|
|
6
|
+
* Faster base64FromBytes & bytesFromBase64 on Node.JS ([#649](https://github.com/stephenh/ts-proto/issues/649)) ([82ab341](https://github.com/stephenh/ts-proto/commit/82ab341557fba1a4933c4613d5c20dbf897905fa))
|
|
7
|
+
|
|
1
8
|
## [1.121.3](https://github.com/stephenh/ts-proto/compare/v1.121.2...v1.121.3) (2022-08-06)
|
|
2
9
|
|
|
3
10
|
|
package/build/main.js
CHANGED
|
@@ -290,24 +290,30 @@ function makeByteUtils() {
|
|
|
290
290
|
})();
|
|
291
291
|
`);
|
|
292
292
|
const bytesFromBase64 = (0, ts_poet_1.conditionalOutput)('bytesFromBase64', (0, ts_poet_1.code) `
|
|
293
|
-
const atob: (b64: string) => string = ${globalThis}.atob || ((b64) => ${globalThis}.Buffer.from(b64, 'base64').toString('binary'));
|
|
294
293
|
function bytesFromBase64(b64: string): Uint8Array {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
294
|
+
if (${globalThis}.Buffer) {
|
|
295
|
+
return Uint8Array.from(${globalThis}.Buffer.from(b64, 'base64'));
|
|
296
|
+
} else {
|
|
297
|
+
const bin = ${globalThis}.atob(b64);
|
|
298
|
+
const arr = new Uint8Array(bin.length);
|
|
299
|
+
for (let i = 0; i < bin.length; ++i) {
|
|
300
|
+
arr[i] = bin.charCodeAt(i);
|
|
301
|
+
}
|
|
302
|
+
return arr;
|
|
299
303
|
}
|
|
300
|
-
return arr;
|
|
301
304
|
}
|
|
302
305
|
`);
|
|
303
306
|
const base64FromBytes = (0, ts_poet_1.conditionalOutput)('base64FromBytes', (0, ts_poet_1.code) `
|
|
304
|
-
const btoa : (bin: string) => string = ${globalThis}.btoa || ((bin) => ${globalThis}.Buffer.from(bin, 'binary').toString('base64'));
|
|
305
307
|
function base64FromBytes(arr: Uint8Array): string {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
308
|
+
if (${globalThis}.Buffer) {
|
|
309
|
+
return ${globalThis}.Buffer.from(arr).toString('base64')
|
|
310
|
+
} else {
|
|
311
|
+
const bin: string[] = [];
|
|
312
|
+
arr.forEach((byte) => {
|
|
313
|
+
bin.push(String.fromCharCode(byte));
|
|
314
|
+
});
|
|
315
|
+
return ${globalThis}.btoa(bin.join(''));
|
|
316
|
+
}
|
|
311
317
|
}
|
|
312
318
|
`);
|
|
313
319
|
return { globalThis, bytesFromBase64, base64FromBytes };
|