https://github.com/prantlf/go-sizeio
Extends readers with an additional method Size returning the size of the reader content.
https://github.com/prantlf/go-sizeio
go go-module go-package reader size
Last synced: about 1 year ago
JSON representation
Extends readers with an additional method Size returning the size of the reader content.
- Host: GitHub
- URL: https://github.com/prantlf/go-sizeio
- Owner: prantlf
- License: mit
- Created: 2020-11-13T11:51:28.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-01-29T12:51:30.000Z (over 4 years ago)
- Last Synced: 2025-02-01T10:43:04.883Z (over 1 year ago)
- Topics: go, go-module, go-package, reader, size
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# go-sizeio
[](https://pkg.go.dev/github.com/prantlf/go-sizeio)
[](https://github.com/prantlf/go-sizeio/actions)
[](https://codecov.io/gh/prantlf/go-sizeio)
Extends [readers] with an additional method [Size] returning the size of the reader content. See the [documentation] for more information.
## Installation
Add this package to `go.mod` and `go.sub` in your Go project:
go get github.com/prantlf/go-sizeio
## Usage
Use convenience methods to create readers with the extra `Size` method:
```go
import "github.com/prantlf/go-sizeio"
// get a file reader/closer with the size available right away
readerWithSize := sizeio.OpenFile("...")
// get a general reader with the size known ahead
readerWithSize := sizeio.SizeReader(otherReader, 456)
// test any reader whether it supports the Size method
_, ok := someReader.(sizeio.WithSize)
// get the size of the reader content
size := readerWithSize.Size() // returns 456 as in64
```
See the [documentation] for the full interface.
[readers]: https://golang.org/pkg/io/#Reader
[Size]: https://pkg.go.dev/github.com/prantlf/go-sizeio/#WithSize
[documentation]: https://pkg.go.dev/github.com/prantlf/go-sizeio#section-documentation