Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rosylilly/pio

io with progress
https://github.com/rosylilly/pio

golang golang-library io

Last synced: 5 days ago
JSON representation

io with progress

Awesome Lists containing this project

README

        

# pio - io with progress

[![Go Reference](https://pkg.go.dev/badge/github.com/rosylilly/pio.svg)](https://pkg.go.dev/github.com/rosylilly/pio)
[![test](https://github.com/rosylilly/pio/actions/workflows/test.yml/badge.svg)](https://github.com/rosylilly/pio/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/rosylilly/pio/branch/main/graph/badge.svg?token=kMUjFmnxRY)](https://codecov.io/gh/rosylilly/pio)

## Example

```golang
package main

import (
"bytes"
"errors"
"fmt"
"io"
"log"
"os"

"github.com/rosylilly/pio"
)

func main() {
file, err := os.Open("README.md")
if err != nil {
log.Fatalln(err)
}

logger := log.New(os.Stdout, "", log.Ltime)
reader, err := pio.NewReader(file, pio.WithLogger(logger))
if err != nil {
log.Fatalln(err)
}

buffer := bytes.NewBuffer([]byte{})
for {
_, err := io.CopyN(buffer, reader, 100)
if err != nil {
if errors.Is(err, io.EOF) {
break
} else {
log.Fatalln(err)
}
}
}

fmt.Println(buffer.String())
}
```

[![asciicast](https://asciinema.org/a/405916.svg)](https://asciinema.org/a/405916)

## License

[MIT License](https://github.com/rosylilly/pio/blob/main/LICENSE)