0xc0d / go-fold

A Go implementation of fold command (unix) around io.Reader

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-fold

PkgGoDev

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

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

About

A Go implementation of fold command (unix) around io.Reader

License:MIT License


Languages

Language:Go 100.0%