{"id":17486798,"url":"https://github.com/sumolari/stream-size","last_synced_at":"2026-03-16T16:03:14.917Z","repository":{"id":40793181,"uuid":"284412211","full_name":"Sumolari/stream-size","owner":"Sumolari","description":"Get the size of a stream and abort it if threshold is reached","archived":false,"fork":false,"pushed_at":"2024-08-30T04:45:15.000Z","size":732,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-09-18T17:12:06.532Z","etag":null,"topics":["content-length","nodejs","stream-processing","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Sumolari.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-02T07:20:03.000Z","updated_at":"2024-08-30T04:45:18.000Z","dependencies_parsed_at":"2024-06-16T14:27:33.515Z","dependency_job_id":"8ddb132c-1841-4b8f-afc3-94bab88be931","html_url":"https://github.com/Sumolari/stream-size","commit_stats":{"total_commits":25,"total_committers":2,"mean_commits":12.5,"dds":0.36,"last_synced_commit":"b98a6133cc577abc0bd9519120558d9e51c62762"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sumolari%2Fstream-size","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sumolari%2Fstream-size/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sumolari%2Fstream-size/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sumolari%2Fstream-size/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sumolari","download_url":"https://codeload.github.com/Sumolari/stream-size/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":220445604,"owners_count":16648565,"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":["content-length","nodejs","stream-processing","typescript"],"created_at":"2024-10-19T02:12:01.266Z","updated_at":"2026-03-16T16:03:14.911Z","avatar_url":"https://github.com/Sumolari.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm](https://img.shields.io/npm/v/stream-size)](https://www.npmjs.com/package/stream-size)\n[![codecov](https://codecov.io/gh/Sumolari/stream-size/graph/badge.svg?token=NTFRNMCEGO)](https://codecov.io/gh/Sumolari/stream-size)\n[![NPM](https://img.shields.io/npm/l/stream-size)](https://www.npmjs.com/package/stream-size)\n\n`stream-size` is a non-destructive transformation for Node.js streams that adds a `sizeInBytes` property to your streams.\n\nIt also allows you to limit streams exceeding a maximum size.\n\n## Usage\n\n```ts\nimport { Readable } from 'stream';\nimport { createWriteStream } from 'fs';\nimport getSizeTransform from 'stream-size';\n\nconst MAX_SIZE_ALLOWED_IN_BYTES = 10 * 1024 * 1024; // 10 MB\n\nconst downloadResource = (resourceInputStream: Readable) =\u003e {\n  // Note that no maximum size is required, if you don't pass a value the stream won't be limited.\n  const pipedStream = resourceInputStream.pipe(\n    getSizeTransform(MAX_SIZE_ALLOWED_IN_BYTES),\n  );\n\n  const localFileWriteStream = createWriteStream('temp-file');\n  pipedStream.pipe(localFileWriteStream);\n\n  localFileWriteStream.on('close', () =\u003e {\n    console.log(\n      `Input resource completed read! It has ${pipedStream.sizeInBytes} bytes.`,\n    );\n    // Now you can do something with 'tmp-file' if you want\n  });\n};\n```\n\n## Use cases\n\nSometimes you need a remote resource content-length but the server does not send back that header.\nThis usually happens when trying to upload a third-party resource to an S3 bucket.\n\nIn order to get the size of the resource you can pipe it to the local machine filesystem and get the size, however, if the resource is provided by a malicious actor you could end up filling your machine's disk and crashing the system.\n\nTo prevent that you need to stop downloading the resource when a maximum size is reached.\n\nThis package supports it, as well as directly returning the content-length of the input stream in a single operation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsumolari%2Fstream-size","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsumolari%2Fstream-size","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsumolari%2Fstream-size/lists"}