Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-fetch-progress

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-fetch-progress - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

README.md

47

dist/index.js
"use strict";
var _distance_in_words_to_now = _interopRequireDefault(require("date-fns/distance_in_words_to_now"));
var _add_seconds = _interopRequireDefault(require("date-fns/add_seconds"));
var _throttleDebounce = require("throttle-debounce");
var _bytes = _interopRequireDefault(require("bytes"));
var _events = _interopRequireDefault(require("events"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

@@ -21,13 +33,2 @@

var distanceInWordsToNow = require("date-fns/distance_in_words_to_now");
var addSeconds = require("date-fns/add_seconds");
var _require = require("throttle-debounce"),
throttle = _require.throttle;
var bytes = require("bytes");
var EventEmitter = require("events");
var Progress =

@@ -45,14 +46,14 @@ /*#__PURE__*/

_this.options = options || {};
_this.total = Number(response.headers.get("content-length"));
_this.total = Number(response.headers.get('content-length'));
_this.done = 0;
_this.startedAt = Date.now();
var throttled = throttle(_this.options.throttle || 0, _this.onProgress.bind(_assertThisInitialized(_assertThisInitialized(_this))));
response.body.on("data", function (chunk) {
var throttled = (0, _throttleDebounce.throttle)(_this.options.throttle || 0, _this.onProgress.bind(_assertThisInitialized(_assertThisInitialized(_this))));
response.body.on('data', function (chunk) {
_this.done += chunk.length;
return throttled();
});
response.body.on("end", function () {
response.body.on('end', function () {
_this.onProgress();
_this.emit("finish");
_this.emit('finish');
});

@@ -66,15 +67,15 @@ return _this;

function onProgress() {
var totalh = bytes(this.total);
var doneh = bytes(this.done);
var totalh = (0, _bytes["default"])(this.total);
var doneh = (0, _bytes["default"])(this.done);
var elapsed = (Date.now() - this.startedAt) / 1000;
var rate = this.done / elapsed;
var rateh = bytes(rate) + "/s";
var rateh = "".concat((0, _bytes["default"])(rate), "/s");
var estimated = this.total / rate;
var progress = this.done / this.total;
var eta = estimated - elapsed;
var etaDate = addSeconds(new Date(), eta);
var etah = distanceInWordsToNow(etaDate, {
var etaDate = (0, _add_seconds["default"])(new Date(), eta);
var etah = (0, _distance_in_words_to_now["default"])(etaDate, {
includeSeconds: true
});
this.emit("progress", {
this.emit('progress', {
total: this.total,

@@ -101,4 +102,4 @@ done: this.done,

return Progress;
}(EventEmitter);
}(_events["default"]);
module.exports = Progress;
{
"name": "node-fetch-progress",
"version": "1.0.0",
"version": "1.0.1",
"main": "dist/index.js",
"autor": "Michael Albertz <michael@prio.one>",
"license": "MIT",

@@ -61,3 +62,18 @@ "dependencies": {

]
}
},
"engines": {
"node": ">=8"
},
"keywords": [
"fetch",
"progress"
],
"repository": {
"type": "git",
"url": "git+https://github.com/prioe/node-fetch-progress.git"
},
"bugs": {
"url": "https://github.com/prioe/node-fetch-progress/issues"
},
"homepage": "https://github.com/prioe/node-fetch-progress#readme"
}

@@ -1,14 +0,14 @@

const distanceInWordsToNow = require("date-fns/distance_in_words_to_now");
const addSeconds = require("date-fns/add_seconds");
const { throttle } = require("throttle-debounce");
const bytes = require("bytes");
const EventEmitter = require("events");
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now'
import addSeconds from 'date-fns/add_seconds'
import { throttle } from 'throttle-debounce'
import bytes from 'bytes'
import EventEmitter from 'events'
class Progress extends EventEmitter {
constructor(response, options) {
super();
this.options = options || {};
this.total = Number(response.headers.get("content-length"));
this.done = 0;
this.startedAt = Date.now();
constructor (response, options) {
super()
this.options = options || {}
this.total = Number(response.headers.get('content-length'))
this.done = 0
this.startedAt = Date.now()

@@ -18,28 +18,28 @@ const throttled = throttle(

this.onProgress.bind(this)
);
)
response.body.on("data", chunk => {
this.done += chunk.length;
return throttled();
});
response.body.on('data', (chunk) => {
this.done += chunk.length
return throttled()
})
response.body.on("end", () => {
this.onProgress();
this.emit("finish");
});
response.body.on('end', () => {
this.onProgress()
this.emit('finish')
})
}
onProgress() {
const totalh = bytes(this.total);
const doneh = bytes(this.done);
const elapsed = (Date.now() - this.startedAt) / 1000;
const rate = this.done / elapsed;
const rateh = bytes(rate) + "/s";
const estimated = this.total / rate;
const progress = this.done / this.total;
const eta = estimated - elapsed;
const etaDate = addSeconds(new Date(), eta);
const etah = distanceInWordsToNow(etaDate, { includeSeconds: true });
onProgress () {
const totalh = bytes(this.total)
const doneh = bytes(this.done)
const elapsed = (Date.now() - this.startedAt) / 1000
const rate = this.done / elapsed
const rateh = `${bytes(rate)}/s`
const estimated = this.total / rate
const progress = this.done / this.total
const eta = estimated - elapsed
const etaDate = addSeconds(new Date(), eta)
const etah = distanceInWordsToNow(etaDate, { includeSeconds: true })
this.emit("progress", {
this.emit('progress', {
total: this.total,

@@ -58,6 +58,6 @@ done: this.done,

etaDate
});
})
}
}
module.exports = Progress;
module.exports = Progress
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc