concat

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2020 License: GPL-3.0, MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package concat is a utility package that concatenates multiple files into one with optional date dependency checking.

examples:

// check if file is older than files in a directory
if IsOlderThanDirectory("parts.txt", ".") {
	fmt.Println("parts.txt needs update")
} else {
	fmt.Println("parts.txt up to date")
}

// check if file is older than files matching a shell glob pattern
if IsOlderThanGlob("parts.txt", "part[0-9].txt") {
	fmt.Println("parts.txt needs update")
} else {
	fmt.Println("parts.txt up to date")
}

// concat files:
err := Concat("concat.txt", "part[0-9].txt", nil)

// concat files, wrapping them in a json object with the filename as key:
if err := Concat("big.json", "json[0-9].json", JsonObjectWrapper); err != nil {
	log.Fatal(err)
}

// concat files, wrapping them in a json array:
if err := Concat("big.json", "json[0-9].json", JsonArrayWrapper); err != nil {
	log.Fatal(err)
}

Index

Constants

View Source
const (
	// Use system temp directory or current working directory for temp files
	UseTemp = true

	// Error or skip on non-fatal errors
	SkipOnError = false
)

Variables

View Source
var JsonArrayWrapper = &Options{
	atStart:   "[\n",
	atEnd:     "]\n",
	afterEach: ",\n",
	skipLast:  true,
}

JsonArrayWrapper is an Options struct predefined for concatenating Json files into a new array.

View Source
var JsonObjectWrapper = &Options{
	atStart:   "{\n",
	atEnd:     "}\n",
	afterEach: ",\n",
	skipLast:  true,

	beforeEachFunc: func(fn string) string {
		fmt.Println("beforeEachFunc:", fn)
		return `"` + strings.TrimSuffix(filepath.Base(fn), filepath.Ext(fn)) + `":`
	},
}

JsonObjectWrapper is an Options struct predefined for concatenating Json files into a new object with the filename as key.

Functions

func Concat

func Concat(outname, glob string, options *Options) error

Concat concatenates files into a new, large file. It takes an Options struct to define separators between concatenated files.

func Copy

func Copy(in, out string) error

Copy (surprisingly) copies a file to another location, possibly overwriting existing files. It doesn't use Link/Rename so works across file system boundaries.

func IsOlderThanDirectory

func IsOlderThanDirectory(bundlename, dirname string) (bool, error)

IsOlderThanDirectory checks if a given file is older than any of the files in a given directory. If the file doesn't exist, this function returns true.

func IsOlderThanGlob

func IsOlderThanGlob(bundlename, glob string) (bool, error)

IsOlderThanGlob checks if a given file is older than the files matching the glob pattern. If the file doesn't exist, this function returns true.

Types

type Options

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

Options struct specifies optional arguments to the Concat function for defining separating text.

Jump to

Keyboard shortcuts

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