{"id":16307110,"url":"https://github.com/fujiwara/shapeio","last_synced_at":"2025-04-12T22:31:38.207Z","repository":{"id":44463353,"uuid":"55217591","full_name":"fujiwara/shapeio","owner":"fujiwara","description":"Traffic shaper for Golang io.Reader and io.Writer","archived":false,"fork":false,"pushed_at":"2022-02-18T17:09:50.000Z","size":12,"stargazers_count":126,"open_issues_count":2,"forks_count":18,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-11T21:12:42.479Z","etag":null,"topics":["go","golang","traffic-shaping"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fujiwara.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["fujiwara"]}},"created_at":"2016-04-01T08:51:01.000Z","updated_at":"2024-08-23T09:28:20.000Z","dependencies_parsed_at":"2022-08-28T17:01:43.300Z","dependency_job_id":null,"html_url":"https://github.com/fujiwara/shapeio","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fujiwara%2Fshapeio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fujiwara%2Fshapeio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fujiwara%2Fshapeio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fujiwara%2Fshapeio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fujiwara","download_url":"https://codeload.github.com/fujiwara/shapeio/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248640040,"owners_count":21137962,"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":["go","golang","traffic-shaping"],"created_at":"2024-10-10T21:12:32.905Z","updated_at":"2025-04-12T22:31:38.179Z","avatar_url":"https://github.com/fujiwara.png","language":"Go","funding_links":["https://github.com/sponsors/fujiwara"],"categories":[],"sub_categories":[],"readme":"# shapeio\n\nTraffic shaper for Golang io.Reader and io.Writer\n\n```go\nimport \"github.com/fujiwara/shapeio\"\n\nfunc ExampleReader() {\n\t// example for downloading http body with rate limit.\n\tresp, _ := http.Get(\"http://example.com\")\n\tdefer resp.Body.Close()\n\n\treader := shapeio.NewReader(resp.Body)\n\treader.SetRateLimit(1024 * 10) // 10KB/sec\n\tio.Copy(ioutil.Discard, reader)\n}\n\nfunc ExampleWriter() {\n\t// example for writing file with rate limit.\n\tsrc := bytes.NewReader(bytes.Repeat([]byte{0}, 32*1024)) // 32KB\n\tf, _ := os.Create(\"/tmp/foo\")\n\twriter := shapeio.NewWriter(f)\n\twriter.SetRateLimit(1024 * 10) // 10KB/sec\n\tio.Copy(writer, src)\n\tf.Close()\n}\n```\n\n## Usage\n\n#### type Reader\n\n```go\ntype Reader struct {\n}\n```\n\n\n#### func  NewReader\n\n```go\nfunc NewReader(r io.Reader) *Reader\n```\nNewReader returns a reader that implements io.Reader with rate limiting.\n\n#### func (*Reader) Read\n\n```go\nfunc (s *Reader) Read(p []byte) (int, error)\n```\nRead reads bytes into p.\n\n#### func (*Reader) SetRateLimit\n\n```go\nfunc (s *Reader) SetRateLimit(l float64)\n```\nSetRateLimit sets rate limit (bytes/sec) to the reader.\n\n#### type Writer\n\n```go\ntype Writer struct {\n}\n```\n\n\n#### func  NewWriter\n\n```go\nfunc NewWriter(w io.Writer) *Writer\n```\nNewWriter returns a writer that implements io.Writer with rate limiting.\n\n#### func (*Writer) SetRateLimit\n\n```go\nfunc (s *Writer) SetRateLimit(l float64)\n```\nSetRateLimit sets rate limit (bytes/sec) to the writer.\n\n#### func (*Writer) Write\n\n```go\nfunc (s *Writer) Write(p []byte) (int, error)\n```\nWrite writes bytes from p.\n\n##  License\n\nThe MIT License (MIT)\n\nCopyright (c) 2016 FUJIWARA Shunichiro\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffujiwara%2Fshapeio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffujiwara%2Fshapeio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffujiwara%2Fshapeio/lists"}