test-buffer-safe-unsafe.js 540B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. var Buffer = require('../../').Buffer;
  3. var assert = require('assert');
  4. var safe = Buffer.alloc(10);
  5. function isZeroFilled(buf) {
  6. for (var n = 0; n < buf.length; n++)
  7. if (buf[n] !== 0) return false;
  8. return true;
  9. }
  10. assert(isZeroFilled(safe));
  11. // Test that unsafe allocations doesn't affect subsequent safe allocations
  12. Buffer.allocUnsafe(10);
  13. assert(isZeroFilled(new Float64Array(10)));
  14. new Buffer(10);
  15. assert(isZeroFilled(new Float64Array(10)));
  16. Buffer.allocUnsafe(10);
  17. assert(isZeroFilled(Buffer.alloc(10)));