You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test-buffer-zero-fill-cli.js 801B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. var Buffer = require('../../').Buffer;
  3. // Flags: --zero-fill-buffers
  4. // when using --zero-fill-buffers, every Buffer and SlowBuffer
  5. // instance must be zero filled upon creation
  6. var SlowBuffer = require('../../').SlowBuffer;
  7. var assert = require('assert');
  8. function isZeroFilled(buf) {
  9. for (var n = 0; n < buf.length; n++)
  10. if (buf[n] > 0) return false;
  11. return true;
  12. }
  13. // This can be somewhat unreliable because the
  14. // allocated memory might just already happen to
  15. // contain all zeroes. The test is run multiple
  16. // times to improve the reliability.
  17. for (var i = 0; i < 50; i++) {
  18. var bufs = [
  19. Buffer.alloc(20),
  20. Buffer.allocUnsafe(20),
  21. SlowBuffer(20),
  22. Buffer(20),
  23. new SlowBuffer(20)
  24. ];
  25. for (var buf of bufs) {
  26. assert(isZeroFilled(buf));
  27. }
  28. }