{"id":13526555,"url":"https://github.com/freeall/progress-stream","last_synced_at":"2025-04-12T14:57:24.852Z","repository":{"id":12447812,"uuid":"15107293","full_name":"freeall/progress-stream","owner":"freeall","description":"Read the progress of a stream","archived":false,"fork":false,"pushed_at":"2017-04-11T09:06:48.000Z","size":27,"stargazers_count":234,"open_issues_count":12,"forks_count":33,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-03T14:11:12.748Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/freeall.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-11T12:54:12.000Z","updated_at":"2024-08-30T11:29:10.000Z","dependencies_parsed_at":"2022-09-01T23:31:36.197Z","dependency_job_id":null,"html_url":"https://github.com/freeall/progress-stream","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freeall%2Fprogress-stream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freeall%2Fprogress-stream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freeall%2Fprogress-stream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freeall%2Fprogress-stream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/freeall","download_url":"https://codeload.github.com/freeall/progress-stream/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248586250,"owners_count":21128997,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T06:01:31.474Z","updated_at":"2025-04-12T14:57:24.828Z","avatar_url":"https://github.com/freeall.png","language":"JavaScript","readme":"# progress-stream\n\nRead the progress of a stream. Supports speed and eta.\n\nGets the length of the stream automatically if you're using the request or http module. You can also pass the length on initiation. Progress-stream will also check to see if the stream already has a length property.\n\n\tnpm install progress-stream\n\n## Usage\n\nThis example copies a large file, and prints out the percentage, speed and remaining every 100ms.\n\n```js\nvar progress = require('progress-stream');\nvar fs = require('fs');\n\nvar stat = fs.statSync(filename);\nvar str = progress({\n\tlength: stat.size,\n\ttime: 100 /* ms */\n});\n\nstr.on('progress', function(progress) {\n\tconsole.log(progress);\n\n\t/*\n\t{\n\t\tpercentage: 9.05,\n\t\ttransferred: 949624,\n\t\tlength: 10485760,\n\t\tremaining: 9536136,\n\t\teta: 42,\n\t\truntime: 3,\n\t\tdelta: 295396,\n\t\tspeed: 949624\n\t}\n\t*/\n});\n\nfs.createReadStream(filename)\n\t.pipe(str)\n\t.pipe(fs.createWriteStream(output));\n```\n\n## Methods\n\n### progress([options], [onprogress])\n\nYou can instantiate in two ways:\n\n``` js\nvar str = progress({time:100});\nstr.on('progress', function(progress) { ... });\n```\n\nor inline the progress listener\n\n``` js\nvar str = progress({time:100}, function(progress) { ... });\n```\n\n## Properties\n\n### .progress()\n\nYou can get the progress from the progress function.\n\n``` js\nvar str = progress({time:100});\n\nconsole.log(str.progress());\n\n/*\n{\n\tpercentage: 9.05,\n\ttransferred: 949624,\n\tlength: 10485760,\n\tremaining: 9536136,\n\teta: 10,\n\truntime: 0,\n\tdelta: 295396,\n\tspeed: 949624\n}\n*/\n```\n\n## Events\n\n### on('progress', function(progress) { ... })\n\n``` js\nvar str = progress({time:100});\nstr.on('progress', function(progress) { ... });\n```\n\n## Options\n\n### time(integer)\n\nSets how often progress events are emitted in ms. If omitted then the default is to do so every time a chunk is received.\n\n### speed(integer)\n\nSets how long the speedometer needs to calculate the speed. Defaults to 5 sec.\n\n### length(integer)\n\nIf you already know the length of the stream, then you can set it. Defaults to 0.\n\n### drain(boolean)\n\nIn case you don't want to include a readstream after progress-stream, set to true to drain automatically. Defaults to false.\n\n### transferred(integer)\n\nIf you want to set the size of previously downloaded data. Useful for a resumed download.\n\n## Examples\n\n### Using the request module\n\nThis example uses request to download a 100 MB file, and writes out the percentage every second.\n\nYou can also find an example in `test/request.js`.\n\n``` js\nvar progress = require('progress-stream');\nvar req = require('request');\nvar fs = require('fs');\n\nvar str = progress({\n\ttime: 1000\n});\n\nstr.on('progress', function(progress) {\n\tconsole.log(Math.round(progress.percentage)+'%');\n});\n\nreq('http://cachefly.cachefly.net/100mb.test', { headers: { 'user-agent': 'test' }})\n\t.pipe(str)\n\t.pipe(fs.createWriteStream('test.data'));\n```\n\n### Using the http module\n\nIn `test/http.js` it's shown how to do it with the http module.\n\n\n## Methods\n\n\n### `setLength(newLength)`\n\nSometimes, you don't know how big a stream is right away (e.g. multipart file uploads).  You might find out after a few chunks have already passed through the stream, seconds or even minutes later.  In this case, you can use the `setLength` method to recalculate the relevant tracked progress data.\n\n```js\nvar str = progress({});\nsomeFickleStreamInstance.pipe(str).pipe(fs.createWriteStream('test.data'));\n\nsomeFickleStreamInstance.on('conviction', function nowIKnowMyLength (actualLength) {\n  str.setLength(actualLength);\n});\n```\n","funding_links":[],"categories":["Repository","Modules"],"sub_categories":["Streams"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreeall%2Fprogress-stream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreeall%2Fprogress-stream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreeall%2Fprogress-stream/lists"}