splice.js 366 B

123456789101112131415161718
  1. var Buffers = require('buffers');
  2. var bufs = Buffers([
  3. new Buffer([1,2,3]),
  4. new Buffer([4,5,6,7]),
  5. new Buffer([8,9,10]),
  6. ]);
  7. var removed = bufs.splice(2, 4, new Buffer('ab'), new Buffer('cd'));
  8. console.dir({
  9. removed : removed.slice(),
  10. bufs : bufs.slice(),
  11. });
  12. /* Output:
  13. { removed: <Buffer 03 04 05 06>,
  14. bufs: <Buffer 01 02 07 08 09 0a> }
  15. */