{"id":48994794,"url":"https://github.com/turtlemonvh/altscanner","last_synced_at":"2026-04-18T16:12:08.270Z","repository":{"id":57483902,"uuid":"53150025","full_name":"turtlemonvh/altscanner","owner":"turtlemonvh","description":"A version of `bufio.Scanner` that works for lines of arbitrary length.","archived":false,"fork":false,"pushed_at":"2016-12-23T18:19:20.000Z","size":10,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-13T19:39:12.212Z","etag":null,"topics":["buffer","go","scanner"],"latest_commit_sha":null,"homepage":null,"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/turtlemonvh.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":"2016-03-04T16:42:52.000Z","updated_at":"2021-07-26T18:18:22.000Z","dependencies_parsed_at":"2022-08-28T17:02:29.952Z","dependency_job_id":null,"html_url":"https://github.com/turtlemonvh/altscanner","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/turtlemonvh/altscanner","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/turtlemonvh%2Faltscanner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/turtlemonvh%2Faltscanner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/turtlemonvh%2Faltscanner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/turtlemonvh%2Faltscanner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/turtlemonvh","download_url":"https://codeload.github.com/turtlemonvh/altscanner/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/turtlemonvh%2Faltscanner/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31975048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["buffer","go","scanner"],"created_at":"2026-04-18T16:12:05.189Z","updated_at":"2026-04-18T16:12:08.263Z","avatar_url":"https://github.com/turtlemonvh.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AltScanner [![GoDoc](https://godoc.org/github.com/turtlemonvh/altscanner?status.svg)](https://godoc.org/github.com/turtlemonvh/altscanner) [![Build Status](https://travis-ci.org/turtlemonvh/altscanner.png?branch=master)](https://travis-ci.org/turtlemonvh/altscanner)\n\nA version of `bufio.Scanner` that works with lines of arbitrary length.\n\n## Why\n\nIf you're getting a `bufio.Scanner: token too long` error, this may be what you want.\n\n## How\n\nIf your code used to look like this:\n\n```golang\nimport \"bufio\"\n\ns := bufio.NewScanner(myIoReader)\nfor s.Scan() {\n    // Do work\n}\n```\n\nYou can now handle very long lines without errors by changing to:\n\n```golang\nimport \"github.com/turtlemonvh/altscanner\"\n\ns := altscanner.NewAltScanner(myIoReader)\nfor s.Scan() {\n    // Do work\n}\n```\n\n## Caveats\n\n* Only breaks on newlines.\n* Just appends bytes to a byte slice instead of using [a real buffer](https://golang.org/pkg/bytes/#Buffer).\n\n## Alternatives\n\nIf you have a good idea about the size of your data and are running go\u003e1.6 ([where the `Scanner.Buffer` method was introduced](https://golang.org/doc/go1.6#minor_library_changes)), you probably just want to change the size of the buffer used by the scanner.  For example:\n\n    // Create a scanner and resize its buffer to be 10X larger than usual (640 Kb instead of 64 Kb)\n    scanner := bufio.NewScanner(file)\n    scanner.Buffer(make([]byte, bufio.MaxScanTokenSize), bufio.MaxScanTokenSize*10)\n\nHowever, if you need to be compatible with go\u003c1.6 or you really have no idea about the size of your data, this approach works pretty well.\n\n## Performance\n\nIt is robust, but not very fast.  The benchmark results below show the performance of reading in 5 lines of content. The lines used in the tests are either 30 bytes (short) or 300K bytes (long).\n\n```bash\n$ go test -test.bench=Scanner -test.run=^$ -test.benchmem\nBenchmarkBufioScannerSmall-8             1000000          1061 ns/op        4128 B/op          2 allocs/op\nBenchmarkBufferedBufioScannerSmall-8     1000000          1059 ns/op        4128 B/op          2 allocs/op\nBenchmarkAltScannerSmall-8               1000000          1779 ns/op        5824 B/op          8 allocs/op\nBenchmarkBufferedBufioScannerLong-8        50000         28077 ns/op      127008 B/op          6 allocs/op\nBenchmarkAltScannerLong-8                   2000       1142195 ns/op     7032704 B/op         78 allocs/op\nPASS\nok      github.com/turtlemonvh/altscanner   13.458s\n```\n\n`AltScanner` is significantly slower, has many more allocations, and uses significantly more bytes per operation than the buffer `bufio.Scanner`.  In short: it is always faster to use `Scanner.Buffer` to adjust the size of the buffer if you are using go1.6+ and you are confident about the max possible size of an line.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fturtlemonvh%2Faltscanner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fturtlemonvh%2Faltscanner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fturtlemonvh%2Faltscanner/lists"}