Files
homepage-psiXfer/psitransfer-v2.3.0/node_modules/common-streams/lib/RandomStream.js
T
2026-09-01 18:33:56 +00:00

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;