AnonSec Shell
Server IP : 185.86.78.101  /  Your IP : 216.73.216.124
Web Server : Apache
System : Linux 675867-vds-valikoshka1996.gmhost.pp.ua 5.4.0-150-generic #167-Ubuntu SMP Mon May 15 17:35:05 UTC 2023 x86_64
User : www ( 1000)
PHP Version : 7.4.33
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /www/wwwroot/mifepriston.org/node_modules/first-chunk-stream/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /www/wwwroot/mifepriston.org/node_modules/first-chunk-stream/index.js
'use strict';
var util = require('util');
var Duplex = require('readable-stream').Duplex;

function FirstChunkStream(options, cb) {
	var _this = this;
	var _state = {
		sent: false,
		chunks: [],
		size: 0
	};

	if (!(this instanceof FirstChunkStream)) {
		return new FirstChunkStream(options, cb);
	}

	options = options || {};

	if (!(cb instanceof Function)) {
		throw new Error('FirstChunkStream constructor requires a callback as its second argument.');
	}

	if (typeof options.chunkLength !== 'number') {
		throw new Error('FirstChunkStream constructor requires `options.chunkLength` to be a number.');
	}

	if (options.objectMode) {
		throw new Error('FirstChunkStream doesn\'t support `objectMode` yet.');
	}

	Duplex.call(this, options);

	// Initialize the internal state
	_state.manager = createReadStreamBackpressureManager(this);

	// Errors management
	// We need to execute the callback or emit en error dependending on the fact
	// the firstChunk is sent or not
	_state.errorHandler = function firstChunkStreamErrorHandler(err) {
		processCallback(err, Buffer.concat(_state.chunks, _state.size), _state.encoding, function () {});
	};

	this.on('error', _state.errorHandler);

	// Callback management
	function processCallback(err, buf, encoding, done) {
		// When doing sync writes + emiting an errror it can happen that
		// Remove the error listener on the next tick if an error where fired
		// to avoid unwanted error throwing
		if (err) {
			setImmediate(function () {
				_this.removeListener('error', _state.errorHandler);
			});
		} else {
			_this.removeListener('error', _state.errorHandler);
		}

		_state.sent = true;

		cb(err, buf, encoding, function (err, buf, encoding) {
			if (err) {
				setImmediate(function () {
					_this.emit('error', err);
				});
				return;
			}

			if (!buf) {
				done();
				return;
			}

			_state.manager.programPush(buf, encoding, done);
		});
	}

	// Writes management
	this._write = function firstChunkStreamWrite(chunk, encoding, done) {
		_state.encoding = encoding;

		if (_state.sent) {
			_state.manager.programPush(chunk, _state.encoding, done);
		} else if (chunk.length < options.chunkLength - _state.size) {
			_state.chunks.push(chunk);
			_state.size += chunk.length;
			done();
		} else {
			_state.chunks.push(chunk.slice(0, options.chunkLength - _state.size));
			chunk = chunk.slice(options.chunkLength - _state.size);
			_state.size += _state.chunks[_state.chunks.length - 1].length;

			processCallback(null, Buffer.concat(_state.chunks, _state.size), _state.encoding, function () {
				if (!chunk.length) {
					done();
					return;
				}

				_state.manager.programPush(chunk, _state.encoding, done);
			});
		}
	};

	this.on('finish', function firstChunkStreamFinish() {
		if (!_state.sent) {
			return processCallback(null, Buffer.concat(_state.chunks, _state.size), _state.encoding, function () {
				_state.manager.programPush(null, _state.encoding);
			});
		}

		_state.manager.programPush(null, _state.encoding);
	});
}

util.inherits(FirstChunkStream, Duplex);

// Utils to manage readable stream backpressure
function createReadStreamBackpressureManager(readableStream) {
	var manager = {
		waitPush: true,
		programmedPushs: [],
		programPush: function programPush(chunk, encoding, done) {
			done = done || function () {};
			// Store the current write
			manager.programmedPushs.push([chunk, encoding, done]);
			// Need to be async to avoid nested push attempts
			// Programm a push attempt
			setImmediate(manager.attemptPush);
			// Let's say we're ready for a read
			readableStream.emit('readable');
			readableStream.emit('drain');
		},
		attemptPush: function () {
			var nextPush;

			if (manager.waitPush) {
				if (manager.programmedPushs.length) {
					nextPush = manager.programmedPushs.shift();
					manager.waitPush = readableStream.push(nextPush[0], nextPush[1]);
					(nextPush[2])();
				}
			} else {
				setImmediate(function () {
					// Need to be async to avoid nested push attempts
					readableStream.emit('readable');
				});
			}
		}
	};

	// Patch the readable stream to manage reads
	readableStream._read = function streamFilterRestoreRead() {
		manager.waitPush = true;
		// Need to be async to avoid nested push attempts
		setImmediate(manager.attemptPush);
	};

	return manager;
}

module.exports = FirstChunkStream;

Anon7 - 2022
AnonSec Team