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

Top 9.0% on proxy.golang.org

proxy.golang.org : 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.

Registry - Source - Documentation - JSON
purl: pkg:golang/github.com/neilotoole/samplereader
Keywords: bytes , cache , go , golang , io , multireader , multiwriter , reader , stream
License: MIT
Latest release: about 1 year ago
First release: about 4 years ago
Namespace: github.com/neilotoole
Stars: 31 on GitHub
Forks: 0 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 25 days ago

    Loading...
    Readme
    Loading...