We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2a82f81 commit 143a1e4Copy full SHA for 143a1e4
docs/arraybuffer.md
@@ -452,7 +452,17 @@ Float64Array.BYTES_PER_ELEMENT // 8
452
```javascript
453
// ArrayBuffer转为字符串,参数为ArrayBuffer对象
454
function ab2str(buf) {
455
- return String.fromCharCode.apply(null, new Uint16Array(buf));
+ if (buf && buf.byteLength < 128000) { // limit max length avoid overhead
456
+ return String.fromCharCode.apply(null, new Uint16Array(buf));
457
+ }
458
+
459
+ const len = bufView.byteLength;
460
+ const bstr = new Array(len);
461
+ const bufView = new Uint16Array(buf);
462
+ for (let i = 0; i < len; i++) {
463
+ bstr[i] = String.fromCharCode.call(null, bufView[i]);
464
465
+ return bstr.join('');
466
}
467
468
// 字符串转为ArrayBuffer对象,参数为字符串
0 commit comments