Skip to content

golang Reader implementation for overriding ranges of a stream

License

Notifications You must be signed in to change notification settings

carbonin/overreader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go

overreader

Implements a single reader which handles replacing multiple ranges in an underlying reader with separate data.

Usage

package main

import (
	"fmt"
	"io"
	"log"
	"os"
	"strings"

	"github.com/carbonin/overreader"
)

func main() {
	sr := strings.NewReader("12345 ----- abcde ===")

	range1 := &overreader.Range{
		Content: strings.NewReader("67890"),
		Offset:  6,
	}
	range2 := &overreader.Range{
		Content: strings.NewReader("xyz"),
		Offset:  18,
	}

	r, err := overreader.NewReader(sr, range1, range2)
	if err != nil {
		log.Fatal(err)
	}
	if _, err := io.Copy(os.Stdout, r); err != nil {
		log.Fatal(err)
	}
	fmt.Println("")
}

Running the program above results in the output: 12345 67890 abcde xyz

About

golang Reader implementation for overriding ranges of a stream

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages