test-buffer-safe-unsafe.js 540 B

123456789101112131415161718192021222324252627
  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)));