https://github.com/thehungry-dev/ioline
Provides functionality to access IO devices by reading line-by-line
https://github.com/thehungry-dev/ioline
file go golang
Last synced: 5 months ago
JSON representation
Provides functionality to access IO devices by reading line-by-line
- Host: GitHub
- URL: https://github.com/thehungry-dev/ioline
- Owner: thehungry-dev
- License: mit
- Created: 2020-07-19T05:45:23.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-19T16:15:12.000Z (over 5 years ago)
- Last Synced: 2023-12-19T10:59:37.961Z (about 2 years ago)
- Topics: file, go, golang
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# IOLine
Provides functionality to access IO devices by reading line-by-line
## Usage
```go
// Reads line 3 in file `/path`
line, err = ioline.ReadFile("/path", 3)
// Reads line 5 in file `/path`, as well as 2 lines before line 3 and 1 line after line 3
line, err := ioline.ReadFileWithBuffers("/path", 5, 2, 1)
line.FirstLine // 3
line.Before // Lines before line 5 up to the requested amount
line.After // Lines after line 5 up to the requested amount
line.Exact // Line 5 content
line.Count() // Total line read
// Reads a buffer line-by-line, without end-of-line character
scanner := ioline.NewScanner(reader)
// Doesn't iterate in case of errors or when finished
for scanner.Next() {
line := scanner.Get()
fmt.Println(line)
}
scanner.Error() // Last error
scanner.HasError() // True if an error happened
```