Файловый менеджер - Редактировать - /home/freeclou/app.optimyar.com/front-web/build/assets/fonts/iran-yekan/MobileFonts/wgdpf7/delayed-stream.tar
Назад
lib/delayed_stream.js 0000664 00000004417 15104373365 0010651 0 ustar 00 var Stream = require('stream').Stream; var util = require('util'); module.exports = DelayedStream; function DelayedStream() { this.source = null; this.dataSize = 0; this.maxDataSize = 1024 * 1024; this.pauseStream = true; this._maxDataSizeExceeded = false; this._released = false; this._bufferedEvents = []; } util.inherits(DelayedStream, Stream); DelayedStream.create = function(source, options) { var delayedStream = new this(); options = options || {}; for (var option in options) { delayedStream[option] = options[option]; } delayedStream.source = source; var realEmit = source.emit; source.emit = function() { delayedStream._handleEmit(arguments); return realEmit.apply(source, arguments); }; source.on('error', function() {}); if (delayedStream.pauseStream) { source.pause(); } return delayedStream; }; Object.defineProperty(DelayedStream.prototype, 'readable', { configurable: true, enumerable: true, get: function() { return this.source.readable; } }); DelayedStream.prototype.setEncoding = function() { return this.source.setEncoding.apply(this.source, arguments); }; DelayedStream.prototype.resume = function() { if (!this._released) { this.release(); } this.source.resume(); }; DelayedStream.prototype.pause = function() { this.source.pause(); }; DelayedStream.prototype.release = function() { this._released = true; this._bufferedEvents.forEach(function(args) { this.emit.apply(this, args); }.bind(this)); this._bufferedEvents = []; }; DelayedStream.prototype.pipe = function() { var r = Stream.prototype.pipe.apply(this, arguments); this.resume(); return r; }; DelayedStream.prototype._handleEmit = function(args) { if (this._released) { this.emit.apply(this, args); return; } if (args[0] === 'data') { this.dataSize += args[1].length; this._checkIfMaxDataSizeExceeded(); } this._bufferedEvents.push(args); }; DelayedStream.prototype._checkIfMaxDataSizeExceeded = function() { if (this._maxDataSizeExceeded) { return; } if (this.dataSize <= this.maxDataSize) { return; } this._maxDataSizeExceeded = true; var message = 'DelayedStream#maxDataSize of ' + this.maxDataSize + ' bytes exceeded.' this.emit('error', new Error(message)); }; .npmignore 0000664 00000000005 15104373365 0006547 0 ustar 00 test License 0000664 00000002075 15104373365 0006066 0 ustar 00 Copyright (c) 2011 Debuggable Limited <felix@debuggable.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Makefile 0000664 00000000071 15104373365 0006213 0 ustar 00 SHELL := /bin/bash test: @./test/run.js .PHONY: test Readme.md 0000664 00000007437 15104373365 0006307 0 ustar 00 # delayed-stream Buffers events from a stream until you are ready to handle them. ## Installation ``` bash npm install delayed-stream ``` ## Usage The following example shows how to write a http echo server that delays its response by 1000 ms. ``` javascript var DelayedStream = require('delayed-stream'); var http = require('http'); http.createServer(function(req, res) { var delayed = DelayedStream.create(req); setTimeout(function() { res.writeHead(200); delayed.pipe(res); }, 1000); }); ``` If you are not using `Stream#pipe`, you can also manually release the buffered events by calling `delayedStream.resume()`: ``` javascript var delayed = DelayedStream.create(req); setTimeout(function() { // Emit all buffered events and resume underlaying source delayed.resume(); }, 1000); ``` ## Implementation In order to use this meta stream properly, here are a few things you should know about the implementation. ### Event Buffering / Proxying All events of the `source` stream are hijacked by overwriting the `source.emit` method. Until node implements a catch-all event listener, this is the only way. However, delayed-stream still continues to emit all events it captures on the `source`, regardless of whether you have released the delayed stream yet or not. Upon creation, delayed-stream captures all `source` events and stores them in an internal event buffer. Once `delayedStream.release()` is called, all buffered events are emitted on the `delayedStream`, and the event buffer is cleared. After that, delayed-stream merely acts as a proxy for the underlaying source. ### Error handling Error events on `source` are buffered / proxied just like any other events. However, `delayedStream.create` attaches a no-op `'error'` listener to the `source`. This way you only have to handle errors on the `delayedStream` object, rather than in two places. ### Buffer limits delayed-stream provides a `maxDataSize` property that can be used to limit the amount of data being buffered. In order to protect you from bad `source` streams that don't react to `source.pause()`, this feature is enabled by default. ## API ### DelayedStream.create(source, [options]) Returns a new `delayedStream`. Available options are: * `pauseStream` * `maxDataSize` The description for those properties can be found below. ### delayedStream.source The `source` stream managed by this object. This is useful if you are passing your `delayedStream` around, and you still want to access properties on the `source` object. ### delayedStream.pauseStream = true Whether to pause the underlaying `source` when calling `DelayedStream.create()`. Modifying this property afterwards has no effect. ### delayedStream.maxDataSize = 1024 * 1024 The amount of data to buffer before emitting an `error`. If the underlaying source is emitting `Buffer` objects, the `maxDataSize` refers to bytes. If the underlaying source is emitting JavaScript strings, the size refers to characters. If you know what you are doing, you can set this property to `Infinity` to disable this feature. You can also modify this property during runtime. ### delayedStream.dataSize = 0 The amount of data buffered so far. ### delayedStream.readable An ECMA5 getter that returns the value of `source.readable`. ### delayedStream.resume() If the `delayedStream` has not been released so far, `delayedStream.release()` is called. In either case, `source.resume()` is called. ### delayedStream.pause() Calls `source.pause()`. ### delayedStream.pipe(dest) Calls `delayedStream.resume()` and then proxies the arguments to `source.pipe`. ### delayedStream.release() Emits and clears all events that have been buffered up so far. This does not resume the underlaying source, use `delayedStream.resume()` instead. ## License delayed-stream is licensed under the MIT license. package.json 0000664 00000003113 15104373365 0007041 0 ustar 00 { "_args": [ [ "delayed-stream@1.0.0", "/home/freeclou/app.optimyar.com/backend" ] ], "_from": "delayed-stream@1.0.0", "_id": "delayed-stream@1.0.0", "_inBundle": false, "_integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", "_location": "/delayed-stream", "_phantomChildren": {}, "_requested": { "type": "version", "registry": true, "raw": "delayed-stream@1.0.0", "name": "delayed-stream", "escapedName": "delayed-stream", "rawSpec": "1.0.0", "saveSpec": null, "fetchSpec": "1.0.0" }, "_requiredBy": [ "/combined-stream" ], "_resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "_spec": "1.0.0", "_where": "/home/freeclou/app.optimyar.com/backend", "author": { "name": "Felix Geisendörfer", "email": "felix@debuggable.com", "url": "http://debuggable.com/" }, "bugs": { "url": "https://github.com/felixge/node-delayed-stream/issues" }, "contributors": [ { "name": "Mike Atkins", "email": "apeherder@gmail.com" } ], "dependencies": {}, "description": "Buffers events from a stream until you are ready to handle them.", "devDependencies": { "fake": "0.2.0", "far": "0.0.1" }, "engines": { "node": ">=0.4.0" }, "homepage": "https://github.com/felixge/node-delayed-stream", "license": "MIT", "main": "./lib/delayed_stream", "name": "delayed-stream", "repository": { "type": "git", "url": "git://github.com/felixge/node-delayed-stream.git" }, "scripts": { "test": "make test" }, "version": "1.0.0" }
| ver. 1.4 |
Github
|
.
| PHP 8.1.33 | Генерация страницы: 0.05 |
proxy
|
phpinfo
|
Настройка