【发布时间】:2016-02-15 15:08:02
【问题描述】:
Javascript ArrayBuffer 或 TypedArrays 没有任何类型的 appendByte()、appendBytes() 或 appendBuffer() 方法。那么如果我想一次填充一个 ArrayBuffer 值,我该怎么做呢?
var firstVal = 0xAB; // 1 byte
var secondVal = 0x3D7F // 2 bytes
var anotherUint8Array = someArr;
var buffer = new ArrayBuffer(); // I don't know the length yet
var bufferArr = new UInt8Array(buffer);
// following methods do not exist. What are the alternatives for each??
bufferArr.appendByte(firstVal);
bufferArr.appendBytes(secondVal);
bufferArr.appendBuffer(anotherUint8Array);
【问题讨论】:
-
它是一个数组,使用数组语法
r[i]=x例如:github.com/rndme/download/blob/master/download.js#L69 还要查看 Uint8Array 构造函数的语法:developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… - 您需要该数组缓冲区的大小才能使用它就这样…… -
创建后不能修改缓冲区大小
标签: javascript buffer arraybuffer typed-arrays