initial commit
This commit is contained in:
+28
@@ -0,0 +1,28 @@
|
||||
'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;
|
||||
Reference in New Issue
Block a user