28 lines
611 B
JavaScript
28 lines
611 B
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
|
|
var _stream = require('stream');
|
|
|
|
var _crypto = require('crypto');
|
|
|
|
class RandomStream extends _stream.Readable {
|
|
constructor(max) {
|
|
super();
|
|
this.remainingBytes = max;
|
|
}
|
|
_read(requestedSize) {
|
|
if (this.remainingBytes === 0) return this.push(null);
|
|
|
|
const size = Math.min(this.remainingBytes, requestedSize);
|
|
this.remainingBytes -= size;
|
|
|
|
(0, _crypto.randomBytes)(size, (err, buf) => {
|
|
if (err) return this.emit('error', err);
|
|
this.push(buf);
|
|
});
|
|
}
|
|
}
|
|
exports.default = RandomStream; |