https://github.com/0xc0d/go-fold
A Go implementation of fold command (unix) around io.Reader
https://github.com/0xc0d/go-fold
fold go
Last synced: 8 months ago
JSON representation
A Go implementation of fold command (unix) around io.Reader
- Host: GitHub
- URL: https://github.com/0xc0d/go-fold
- Owner: 0xc0d
- License: mit
- Created: 2021-08-19T08:07:59.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-06T11:31:25.000Z (over 4 years ago)
- Last Synced: 2024-12-26T12:09:27.834Z (about 1 year ago)
- Topics: fold, go
- Language: Go
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-fold
[](https://pkg.go.dev/github.com/0xc0d/go-fold?tab=doc)
A Go implementation of fold command (unix) around io.Reader.
# Why
Folding a string is not a hassle but a folding a stream in io.Reader
could be a little bit challenging. The idea for this fold reader started
when we have encountered with an issue in streaming data as an email
message. According to RFC 822:
> Lines of characters in the body MUST be limited to 998 characters,
and SHOULD be limited to 78 characters, excluding the CRLF.
# Install
```
go get github.com/0xc0d/go-fold
```
# Use
```go
package main
import (
"io"
"os"
"strings"
"github.com/0xc0d/go-fold"
)
func main() {
s := strings.Repeat("0", 20)
r := strings.NewReader(s)
foldReader := fold.NewReader(r, 7)
io.Copy(os.Stdout, foldReader)
}
// Output:
// 0000000
// 0000000
// 000000
```