An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

github.com/neilotoole/samplereader

Package samplereader implements a reader mechanism that allows multiple callers to sample some or the entire contents of a source reader, while only reading from the source reader once. This is admittedly a rather arcane need. Let's say we're reading from stdin. For example: In this scenario, myprogram wants to detect the type of data in the file/pipe, and then print it out. The input file could be, let's say, a CSV file, or a TSV file. The obvious approach is to inspect the first few lines of the input, and check if the input is either valid CSV, or valid TSV. After that process, let's say we want to dump out the entire contents of the input. Package samplereader provides a facility to create a Source from an underlying io.Reader (os.Stdin in this scenario), and spawn multiple readers, each of which can operate independently, in their own goroutines if desired. The underlying source (again, os.Stdin in this scenario) will only be read from once, but its data is available to multiple readers, because that data is cached in memory. That is, until there's only one final reader left, (after invoking Source.Seal) at which point the cache is discarded, and the final reader reads straight from the underlying source.

Ecosystem
proxy.golang.org
Latest Release
v0.3.5
almost 2 years ago
Versions
8
Links
Registry proxy.golang.org
Source Repository
Docs Documentation
JSON API View JSON
CodeMeta codemeta.json
Package Details
PURL pkg:golang/github.com/neilotoole/samplereader
spec
License MIT
Namespace github.com/neilotoole
First Release about 5 years ago
Last Synced 19 days ago
Repository
Stars 31 on GitHub
Forks 0 on GitHub
Rankings on proxy.golang.org
Overall Top 9.0%