带偏移量的javascript数组的节点缓冲区

带偏移量的javascript数组的节点缓冲区,javascript,node.js,Javascript,Node.js,我试图将节点缓冲区转换为Uint8ClampedArray,但我想放弃前8个字节。我试着这样做: buf = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); arr = new Uint8ClampedArray(buf, 8, 8); 但它似乎忽略了偏移量,arr包含所有buf 如何将buf转换为以n字节偏移量开始的数组?只需使用Buffer.slice: > arr = new Uint8Cla

我试图将节点缓冲区转换为Uint8ClampedArray,但我想放弃前8个字节。我试着这样做:

buf = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
arr = new Uint8ClampedArray(buf, 8, 8);
但它似乎忽略了偏移量,
arr
包含所有
buf


如何将
buf
转换为以n字节偏移量开始的数组?

只需使用
Buffer.slice

> arr = new Uint8ClampedArray(buf.slice(8));
Uint8ClampedArray [ 9, 10, 11, 12, 13, 14, 15, 16 ]
顺便说一句,用这种方式构造
缓冲区是不可取的:

> buf = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
<Buffer 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10>
[DEP0005] DeprecationWarning: Buffer() is deprecated due to security and 
usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or 
Buffer.from() methods instead.
>buf=新缓冲区([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]);
[DEP0005]弃用警告:由于安全性和
可用性问题。请使用Buffer.alloc()、Buffer.allocUnsafe()或
改为使用Buffer.from()方法。