horzcat

package module
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2021 License: MIT Imports: 5 Imported by: 0

README

horzcat

Package horzcat concatenates multiple files in horizontal direction.

Documentation

Contributing

License

MIT Licensed

© 2021 Parro's Go Packages

Documentation

Overview

Package horzcat concatenates multiple files in horizontal direction. To clarify, consider the following comparison between cat and horzcat of two files:

$ cat a.dat 1.dat
a b
c d
1 2
3 4
$ horzcat -s ' ' a.dat 1.dat
a b 1 2
c d 3 4

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Concat

func Concat(opt Options, sources ...io.Reader) error

Concat read lines from all io.Reader in sources, concatenetes line by line horizontally, and finally writes concateneted lines to options.Target argument. If options.Target is nil, Concat writes to os.Stdout. String opt.Sep is added between lines String opt.Tail is added at the end of every written line.

Example

This example show how to use horzcat.Func()

package main

import (
	"bytes"
	"embed"
	"io/fs"

	"github.com/parrogo/horzcat"
)

//go:embed fixtures
var fixtureRootFS embed.FS
var fixtureFS, _ = fs.Sub(fixtureRootFS, "fixtures")

// This example show how to use horzcat.Func()
func main() {
	var buf1 bytes.Buffer
	var buf2 bytes.Buffer

	buf1.WriteString("ciao\n")
	buf1.WriteString("salve\n")

	buf2.WriteString("Andre\n")
	buf2.WriteString("Parro\n")
	buf2.WriteString("The end\n")

	err := horzcat.Concat(horzcat.Options{
		Sep:  ",",
		Tail: "!",
	}, &buf1, &buf2)
	if err != nil {
		panic(err)
	}
}

// # TODO: enable example tests
Output:

ciao,Andre!
salve,Parro!
The end!

Types

type InputError

type InputError struct {
	// contains filtered or unexported fields
}

InputError wraps an error in order to include the position of failing stream.

func (InputError) Convert

func (e InputError) Convert(filenames []string) error

Convert returns an error that include the name of the file that causes the failure

func (InputError) Error

func (e InputError) Error() string

Error implements error interface

func (InputError) Unwrap

func (e InputError) Unwrap() error

Unwrap returns the wrapped error

type Options

type Options struct {
	Target         io.Writer
	Sep            string
	Tail           string
	SameLinesCount bool
	RowHeaderLen   int
}

Options struct groups all options accepted by Concat.

Target field contains the io.Writer on which to write concateneted lines. When it's nil, os.Stdout is used as writer.

Sep field is a string used to separate lines from source readers.

Tail field is a string appended at the end of every concatenated line.

SameLinesCount field, when set to true, requires that every source has the exact numer of lines. If one or more of the readers has a different lines count, an error is returned. When the field is false, excess lines from one or more reader are still concatened and written to output. Sep string is added alone for each of the readers that miss one or more lines.

RowHeaderLen could be set to the lenght, in bytes, of the row header. If > 0, RowHeaderLen bytes will be skipped from each line of each source reader except the first. When first reader have less lines than the others, row header is always kept for the first reader that has lines.

Directories

Path Synopsis
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL