https://github.com/raspi/searchreader
Search single bytes.Reader with multiple strings.Readers with or without case sensitivity
https://github.com/raspi/searchreader
binary bytes case-sensitive case-sensitivity find go golang library reader search stream string text
Last synced: 5 months ago
JSON representation
Search single bytes.Reader with multiple strings.Readers with or without case sensitivity
- Host: GitHub
- URL: https://github.com/raspi/searchreader
- Owner: raspi
- License: apache-2.0
- Created: 2022-12-30T00:39:29.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-04T13:13:27.000Z (over 2 years ago)
- Last Synced: 2025-01-08T11:42:13.709Z (6 months ago)
- Topics: binary, bytes, case-sensitive, case-sensitivity, find, go, golang, library, reader, search, stream, string, text
- Language: Go
- Homepage:
- Size: 27.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# searchreader



[](https://goreportcard.com/report/github.com/raspi/searchreader)Search single `bytes.Reader` with different `strings.Reader`(s) containing the search byte(s) or string(s).
Part of [heksa issue](https://github.com/raspi/heksa/issues/8).
```go
func main() {// Source
src := bytes.NewReader(
[]byte("heLLo, world!\000\000"),
)// What to search
search1 := strings.NewReader("\000")
search2 := strings.NewReader(`ll`)sr := searchreader.New(src,
searchreader.WithCaseSensitive(search1),
searchreader.WithCaseInsensitive(search2),
)buffer := make([]byte, 1024)
_, results, err := sr.Read(buffer)
if err != nil {
panic(err)
}for _, result := range results {
fmt.Printf(`found match at position %d that matches search%d %d`+"\n", result.StartPosition, 1+result.Index, result.Length)
}}
```Outputs:
```
found match at position 2 that matches search2 2
found match at position 13 that matches search1 1
found match at position 14 that matches search1 1
```## Some goals
* Convert searched string(s) into different encodings such as UTF-8, ISO-8859-1 and ISO-8859-15 so that you can search more efficiently at once
## Is it any good?
Yes.