This commit is contained in:
Lukáš Kaňka
2023-08-15 18:35:50 +02:00
commit ea3e372146
10019 changed files with 2548539 additions and 0 deletions

View File

@ -0,0 +1,15 @@
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
[package.json]
indent_size = 2

63
CyLukTs/lukan/node_modules/request-progress/.jshintrc generated vendored Normal file
View File

@ -0,0 +1,63 @@
{
"predef": [
"console",
"require",
"define",
"describe",
"it",
"before",
"beforeEach",
"after",
"afterEach"
],
"node": true,
"devel": true,
"bitwise": true,
"curly": true,
"eqeqeq": false,
"forin": false,
"immed": true,
"latedef": false,
"newcap": true,
"noarg": true,
"noempty": false,
"nonew": true,
"plusplus": false,
"regexp": true,
"undef": true,
"unused": true,
"quotmark": "single",
"strict": true,
"trailing": true,
"asi": false,
"boss": false,
"debug": false,
"eqnull": true,
"es5": false,
"esnext": false,
"evil": false,
"expr": true,
"funcscope": false,
"globalstrict": false,
"iterator": false,
"lastsemic": false,
"laxbreak": false,
"laxcomma": false,
"loopfunc": true,
"multistr": false,
"onecase": true,
"regexdash": false,
"scripturl": false,
"smarttabs": false,
"shadow": false,
"sub": false,
"supernew": false,
"validthis": false,
"nomen": false,
"onevar": false,
"white": true
}

View File

@ -0,0 +1,4 @@
/node_modules
/npm-debug.*
/test/coverage

View File

@ -0,0 +1,5 @@
language: node_js
node_js:
- "4"
- "5"
script: "npm run test-travis"

19
CyLukTs/lukan/node_modules/request-progress/LICENSE generated vendored Normal file
View File

@ -0,0 +1,19 @@
Copyright (c) 2012 IndigoUnited
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.

78
CyLukTs/lukan/node_modules/request-progress/README.md generated vendored Normal file
View File

@ -0,0 +1,78 @@
# request-progress
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url]
[npm-url]:https://npmjs.org/package/request-progress
[downloads-image]:http://img.shields.io/npm/dm/request-progress.svg
[npm-image]:http://img.shields.io/npm/v/request-progress.svg
[travis-url]:https://travis-ci.org/IndigoUnited/node-request-progress
[travis-image]:http://img.shields.io/travis/IndigoUnited/node-request-progress/master.svg
[coveralls-url]:https://coveralls.io/r/IndigoUnited/node-request-progress
[coveralls-image]:https://img.shields.io/coveralls/IndigoUnited/node-request-progress/master.svg
[david-dm-url]:https://david-dm.org/IndigoUnited/node-request-progress
[david-dm-image]:https://img.shields.io/david/IndigoUnited/node-request-progress.svg
[david-dm-dev-url]:https://david-dm.org/IndigoUnited/node-request-progress#info=devDependencies
[david-dm-dev-image]:https://img.shields.io/david/dev/IndigoUnited/node-request-progress.svg
Tracks the download progress of a request made with [request](https://github.com/mikeal/request), giving insight of various metrics including progress percentage, download speed and time remaining.
## Installation
`$ npm install request-progress`
## Usage
```js
var fs = require('fs');
var request = require('request');
var progress = require('request-progress');
// The options argument is optional so you can omit it
progress(request('https://az412801.vo.msecnd.net/vhd/VMBuild_20141027/VirtualBox/IE11/Windows/IE11.Win8.1.For.Windows.VirtualBox.zip'), {
// throttle: 2000, // Throttle the progress event to 2000ms, defaults to 1000ms
// delay: 1000, // Only start to emit after 1000ms delay, defaults to 0ms
// lengthHeader: 'x-transfer-length' // Length header to use, defaults to content-length
})
.on('progress', function (state) {
// The state is an object that looks like this:
// {
// percent: 0.5, // Overall percent (between 0 to 1)
// speed: 554732, // The download speed in bytes/sec
// size: {
// total: 90044871, // The total payload size in bytes
// transferred: 27610959 // The transferred payload size in bytes
// },
// time: {
// elapsed: 36.235, // The total elapsed seconds since the start (3 decimals)
// remaining: 81.403 // The remaining seconds to finish (3 decimals)
// }
// }
console.log('progress', state);
})
.on('error', function (err) {
// Do something with err
})
.on('end', function () {
// Do something after request finishes
})
.pipe(fs.createWriteStream('IE11.Win8.1.For.Windows.VirtualBox.zip'));
```
If the request's response does not include the `content-length` header, the values of some metrics will be `null`.
Also `speed` and `time.remaining` will be `null` until it can be calculated.
The `state` object emitted in the `progress` event is reused to avoid creating a new object for each event.
If you wish to peek the `state` object at any time, it is available in `request.progressState`.
## Tests
`$ npm test`
`$ npm test-cov` to get coverage report
## License
Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php).

128
CyLukTs/lukan/node_modules/request-progress/index.js generated vendored Normal file
View File

@ -0,0 +1,128 @@
'use strict';
var throttle = require('throttleit');
function onRequest(context) {
// Reset dynamic stuff
context.startedAt = null;
context.state = context.request.progressState = null;
context.delayTimer && clearTimeout(context.delayTimer);
context.delayTimer = null;
}
function onResponse(context, response) {
// Mark start timestamp
context.startedAt = Date.now();
// Create state
// Also expose the state throught the request
// See https://github.com/IndigoUnited/node-request-progress/pull/2/files
context.state = context.request.progressState = {
time: {
elapsed: 0,
remaining: null
},
speed: null,
percent: null,
size: {
total: Number(response.headers[context.options.lengthHeader]) || null,
transferred: 0
}
};
// Delay the progress report
context.delayTimer = setTimeout(function () {
context.delayTimer = null;
}, context.options.delay);
}
function onData(context, data) {
context.state.size.transferred += data.length;
!context.delayTimer && context.reportState();
}
function onEnd(context) {
/* istanbul ignore if */
if (context.delayTimer) {
clearTimeout(context.delayTimer);
context.delayTimer = null;
}
context.request.progressState = context.request.progressContext = null;
}
function reportState(context) {
var state;
// Do nothing if still within the initial delay or if already finished
if (context.delayTimer || !context.request.progressState) {
return;
}
state = context.state;
state.time.elapsed = (Date.now() - context.startedAt) / 1000;
// Calculate speed only if 1s has passed
if (state.time.elapsed >= 1) {
state.speed = state.size.transferred / state.time.elapsed;
}
// Calculate percent & remaining only if we know the total size
if (state.size.total != null) {
state.percent = Math.min(state.size.transferred, state.size.total) / state.size.total;
if (state.speed != null) {
state.time.remaining = state.percent !== 1 ? (state.size.total / state.speed) - state.time.elapsed : 0;
state.time.remaining = Math.round(state.time.remaining * 1000) / 1000; // Round to 4 decimals
}
}
context.request.emit('progress', state);
}
function requestProgress(request, options) {
var context;
if (request.progressContext) {
return request;
}
if (request.response) {
throw new Error('Already got response, it\'s too late to track progress');
}
// Parse options
options = options || {};
options.throttle = options.throttle == null ? 1000 : options.throttle;
options.delay = options.delay || 0;
options.lengthHeader = options.lengthHeader || 'content-length';
// Create context
context = {};
context.request = request;
context.options = options;
context.reportState = throttle(reportState.bind(null, context), options.throttle);
// context.startedAt = null;
// context.state = null;
// context.delayTimer = null;
// Attach listeners
request
.on('request', onRequest.bind(null, context))
.on('response', function handleResponse(response) {
response.on('data', onData.bind(null, context));
return onResponse(context, response);
})
.on('end', onEnd.bind(null, context));
request.progressContext = context;
return request;
}
module.exports = requestProgress;

View File

@ -0,0 +1,41 @@
{
"name": "request-progress",
"version": "3.0.0",
"description": "Tracks the download progress of a request made with mikeal/request, giving insight of various metrics including progress percent, download speed and time remaining",
"main": "index.js",
"dependencies": {
"throttleit": "^1.0.0"
},
"devDependencies": {
"coveralls": "^2.11.6",
"expect.js": "^0.3.1",
"istanbul": "^0.4.1",
"mocha": "^3.0.2"
},
"scripts": {
"test": "mocha --bail",
"test-cov": "istanbul cover --dir test/coverage _mocha -- --bail && echo open test/coverage/lcov-report/index.html",
"test-travis": "istanbul cover _mocha --report lcovonly -- --bail && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
},
"repository": {
"type": "git",
"url": "git://github.com/IndigoUnited/node-request-progress"
},
"bugs": {
"url": "http://github.com/IndigoUnited/node-request-progress/issues"
},
"keywords": [
"progress",
"request",
"mikeal",
"size",
"bytes",
"percent",
"percentage",
"speed",
"eta",
"etr"
],
"author": "IndigoUnited <hello@indigounited.com> (http://indigounited.com)",
"license": "MIT"
}

View File

@ -0,0 +1,385 @@
'use strict';
var expect = require('expect.js');
var EventEmitter = require('events').EventEmitter;
var progress = require('../');
function normalizeStates(states) {
states.forEach(function (state) {
state.time.elapsed = Math.round(state.time.elapsed),
state.time.remaining = state.time.remaining != null ? Math.round(state.time.remaining) : null;
state.speed = state.speed != null ? Math.round(state.speed) : null;
});
}
describe('request-progress', function () {
var request;
var states;
var response;
beforeEach(function () {
states = [];
request = new EventEmitter();
response = new EventEmitter();
request.on('progress', function (state) {
states.push(JSON.parse(JSON.stringify(state)));
});
});
it('should emit the progress event with the correct state information', function (done) {
progress(request, { throttle: 0 })
.on('end', function () {
normalizeStates(states);
expect(states).to.eql([{
percent: 0.5,
speed: null,
size: { total: 10, transferred: 5, },
time: { elapsed: 0, remaining: null }
}, {
percent: 0.8,
speed: 7,
size: { total: 10, transferred: 8 },
time: { elapsed: 1, remaining: 0 }
}, {
percent: 1,
speed: 8,
size: { total: 10, transferred: 10 },
time: { elapsed: 1, remaining: 0 }
}]);
done();
});
request.emit('request');
request.emit('response', Object.assign(response, { headers: { 'content-length': 10 } }));
setTimeout(function () {
response.emit('data', new Buffer('aaaaa'));
}, 25);
setTimeout(function () {
response.emit('data', new Buffer('bbb'));
}, 1150);
setTimeout(function () {
response.emit('data', new Buffer('cc'));
request.emit('end');
}, 1250);
});
it('should provide request.progressState (and request.progressContext)', function (done) {
progress(request, { throttle: 0 })
.on('end', function () {
expect(request.progressState).to.be(null);
expect(request.progressContext).to.be(null);
done();
});
expect(request.progressContext).to.be.an('object');
expect(request.progressState).to.be(undefined);
request.emit('request');
request.emit('response', Object.assign(response, { headers: { 'content-length': 2 } }));
expect(request.progressContext).to.be.an('object');
expect(request.progressState).to.be.an('object');
setTimeout(function () {
response.emit('data', new Buffer('a'));
expect(request.progressContext).to.be.an('object');
expect(request.progressState).to.be.an('object');
expect(request.progressState.percent).to.be(0.5);
}, 25);
setTimeout(function () {
response.emit('data', new Buffer('b'));
expect(request.progressContext).to.be.an('object');
expect(request.progressState).to.be.an('object');
expect(request.progressState.percent).to.be(1);
request.emit('end');
}, 100);
});
it('should have a option.delay default of 0', function () {
progress(request);
expect(request.progressContext.options.delay).to.be(0);
});
it('should respect the passed option.delay', function (done) {
progress(request, { throttle: 0, delay: 250 })
.on('end', function () {
expect(states).to.have.length(2);
expect(states[0].percent).to.be(0.6);
expect(states[1].percent).to.be(1);
done();
});
request.emit('request');
request.emit('response', Object.assign(response, { headers: { 'content-length': 10 } }));
setTimeout(function () {
response.emit('data', new Buffer('aa'));
}, 25);
setTimeout(function () {
response.emit('data', new Buffer('bb'));
}, 200);
setTimeout(function () {
response.emit('data', new Buffer('cc'));
}, 300);
setTimeout(function () {
response.emit('data', new Buffer('dddd'));
request.emit('end');
}, 400);
});
it('should have a option.throttle default of 1000', function () {
progress(request);
expect(request.progressContext.options.throttle).to.be(1000);
});
it('should respect the passed option.throttle', function (done) {
progress(request, { throttle: 300, delay: 0 })
.on('end', function () {
expect(states).to.have.length(3);
expect(states[0].percent).to.be(0.2);
expect(states[1].percent).to.be(0.6);
expect(states[2].percent).to.be(0.9);
done();
});
request.emit('request');
request.emit('response', Object.assign(response, { headers: { 'content-length': 10 } }));
setTimeout(function () {
response.emit('data', new Buffer('aa'));
}, 25);
setTimeout(function () {
response.emit('data', new Buffer('bb'));
}, 100);
setTimeout(function () {
response.emit('data', new Buffer('cc'));
}, 300);
setTimeout(function () {
response.emit('data', new Buffer('dd'));
}, 400);
setTimeout(function () {
response.emit('data', new Buffer('e'));
}, 500);
setTimeout(function () {
response.emit('data', new Buffer('bf'));
request.emit('end');
}, 700);
});
it('should have a option.lengthHeader default of "content-length"', function () {
progress(request);
expect(request.progressContext.options.lengthHeader).to.be('content-length');
});
it('should use option.lengthHeader', function (done) {
progress(request, {
throttle: 0,
lengthHeader: 'x-transfer-length'
})
.on('end', function () {
expect(states).to.have.length(2);
expect(states[0].percent).to.be(0.5);
expect(states[0].size.total).to.be(10);
expect(states[1].percent).to.be(1);
expect(states[1].size.total).to.be(10);
done();
});
request.emit('request');
request.emit('response', Object.assign(response, {
headers: { 'x-transfer-length': 10, 'content-length': 5 }
}));
setTimeout(function () {
response.emit('data', new Buffer('aaaaa'));
}, 25);
setTimeout(function () {
response.emit('data', new Buffer('bbbbb'));
request.emit('end');
}, 200);
});
it('should fail if response is already set', function () {
request.response = { headers: { 'content-length': 10 } };
expect(function () {
progress(request);
}).to.throwException(/too late/);
});
it('should deal with unknown content length', function (done) {
progress(request, { throttle: 0 })
.on('end', function () {
normalizeStates(states);
expect(states).to.eql([{
percent: null,
speed: null,
size: { total: null, transferred: 5, },
time: { elapsed: 0, remaining: null }
}, {
percent: null,
speed: 10,
size: { total: null, transferred: 12, },
time: { elapsed: 1, remaining: null }
}]);
done();
});
request.emit('request');
request.emit('response', Object.assign(response, { headers: {} }));
setTimeout(function () {
response.emit('data', new Buffer('aaaaa'));
}, 25);
setTimeout(function () {
response.emit('data', new Buffer('bbbbbbb'));
request.emit('end');
}, 1150);
});
it('should deal with payloads higher than the content length', function (done) {
progress(request, { throttle: 0 })
.on('end', function () {
normalizeStates(states);
expect(states).to.eql([{
percent: 0.5,
speed: null,
size: { total: 10, transferred: 5, },
time: { elapsed: 0, remaining: null }
}, {
percent: 1,
speed: 10,
size: { total: 10, transferred: 12 },
time: { elapsed: 1, remaining: 0 }
}]);
done();
});
request.emit('request');
request.emit('response', Object.assign(response, { headers: { 'content-length': 10 } }));
setTimeout(function () {
response.emit('data', new Buffer('aaaaa'));
}, 25);
setTimeout(function () {
response.emit('data', new Buffer('bbbbbbb'));
request.emit('end');
}, 1150);
});
it('should not report after the request ends', function (done) {
progress(request, { throttle: 100 });
request.emit('request');
request.emit('response', Object.assign(response, { headers: { 'content-length': 10 } }));
setTimeout(function () {
response.emit('data', new Buffer('aa'));
}, 25);
setTimeout(function () {
response.emit('data', new Buffer('bbbbbbbb'));
request.emit('end');
}, 50);
setTimeout(function () {
normalizeStates(states);
expect(states).to.have.length(1);
expect(states[0].percent).to.be(0.2);
done();
}, 500);
});
it('should not generate duplicate progress events if called twice', function (done) {
progress(request, { throttle: 0 });
progress(request, { throttle: 0 })
.on('end', function () {
expect(states).to.have.length(1);
expect(states[0].percent).to.be(1);
done();
});
request.emit('request');
request.emit('response', Object.assign(response, { headers: { 'content-length': 2 } }));
setTimeout(function () {
response.emit('data', new Buffer('aa'));
request.emit('end');
}, 25);
});
it('should reset stuff on "request" event', function () {
progress(request, { throttle: 0 });
expect(request.progressContext).to.be.an('object');
expect(request.progressState).to.be(undefined);
request.emit('request');
request.emit('response', Object.assign(response, { headers: { 'content-length': 2 } }));
expect(request.progressContext).to.be.an('object');
expect(request.progressState).to.be.an('object');
request.emit('request');
expect(request.progressContext).to.be.an('object');
expect(request.progressState).to.be(null);
});
it('should hook into "data" event from the response and not the request', function (done) {
// See: https://github.com/IndigoUnited/node-request-progress/issues/20
progress(request, { throttle: 0 })
.on('end', function () {
expect(states).to.have.length(2);
expect(states[0].percent).to.be(0.5);
expect(states[1].percent).to.be(1);
done();
});
request.emit('request');
request.emit('response', Object.assign(response, { headers: { 'content-length': 4 } }));
setTimeout(function () {
response.emit('data', new Buffer('aa'));
}, 25);
setTimeout(function () {
request.emit('data', new Buffer('aa'));
}, 50);
setTimeout(function () {
response.emit('data', new Buffer('aa'));
request.emit('end');
}, 100);
});
});