Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nikolaydubina/read-seek-peeker
Go Reader that can Seek() and Peek()
https://github.com/nikolaydubina/read-seek-peeker
bufio golang io reader
Last synced: 2 months ago
JSON representation
Go Reader that can Seek() and Peek()
- Host: GitHub
- URL: https://github.com/nikolaydubina/read-seek-peeker
- Owner: nikolaydubina
- License: mit
- Created: 2024-02-22T04:28:31.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-08-22T09:13:38.000Z (4 months ago)
- Last Synced: 2024-10-09T08:22:51.899Z (3 months ago)
- Topics: bufio, golang, io, reader
- Language: Go
- Homepage:
- Size: 26.4 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
[![codecov](https://codecov.io/gh/nikolaydubina/read-seek-peeker/graph/badge.svg?token=dWs1oSWSRU)](https://codecov.io/gh/nikolaydubina/read-seek-peeker)
[![Go Report Card](https://goreportcard.com/badge/github.com/nikolaydubina/read-seek-peeker)](https://goreportcard.com/report/github.com/nikolaydubina/read-seek-peeker)
[![Go Reference](https://pkg.go.dev/badge/github.com/nikolaydubina/read-seek-peeker#section-readme.svg)](https://pkg.go.dev/github.com/nikolaydubina/read-seek-peeker#section-readme)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/nikolaydubina/read-seek-peeker/badge)](https://securityscorecards.dev/viewer/?uri=github.com/nikolaydubina/read-seek-peeker)```go
type ReadSeekPeeker interface {
Read(p []byte) (n int, err error)
Seek(offset int64, whence int) (int64, error)
Peek(n int) ([]byte, error)
}
``````go
s := "hello beautiful wonderful world!"
r := readseekpeeker.NewBufferedReadSeekPeeker(strings.NewReader(s), 5)b := make([]byte, 5)
r.Read(b)peek, _ := r.Peek(11) // !
r.Seek(21, io.SeekCurrent) // !!
rest, _ := io.ReadAll(r)
fmt.Println(string(b), string(peek), string(rest))
// Output: hello beautiful world!
```As of `2024-02-22`, standard go packages allow either:
A) `Seek()` by [io.ReadSeeker](https://pkg.go.dev/io#ReadSeeker)
B) `Peek()` by [bufio.Reader](https://pkg.go.dev/bufio#Reader.Peek)
..but not both! This package adds that.