gx
chenyc
2025-06-12 7b72ac13a83764a662159d4a49b7fffb90476ecb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env node
var seedrandom = require('../seedrandom');
 
// process.on('SIGPIPE', process.exit);
function epipeBomb(stream, callback) {
  if (stream == null) stream = process.stdout;
  if (callback == null) callback = process.exit;
 
  function epipeFilter(err) {
    if (err.code === 'EPIPE') return callback();
 
    // If there's more than one error handler (ie, us),
    // then the error won't be bubbled up anyway
    if (stream.listeners('error').length <= 1) {
      stream.removeAllListeners();    // Pretend we were never here
      stream.emit('error', err);      // Then emit as if we were never here
      stream.on('error', epipeFilter);// Reattach, ready for the next error!
    }
  }
 
  stream.on('error', epipeFilter);
}
 
epipeBomb();
 
var bufsize = 1024 * 256,
    buf = new Buffer(bufsize * 4),
    prng = seedrandom(0),
    count = parseInt(process.argv[2]) || Infinity;
function dowrite() {
  while (count > 0) {
    for (var j = 0; j < bufsize; ++j) {
      buf.writeUInt32BE(Math.floor(
          prng() * 256 * 256 * 256 * 256
      ), j * 4);
    }
    count -= bufsize * 32;
    if (!process.stdout.write(buf)) {
      process.stdout.once('drain', function() { setTimeout(dowrite, 0) });
      return;
    }
  }
}
 
dowrite();