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 ¶
const ( // Use system temp directory or current working directory for temp files UseTemp = true // Error or skip on non-fatal errors SkipOnError = false )
Variables ¶
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.
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 ¶
Concat concatenates files into a new, large file. It takes an Options struct to define separators between concatenated files.
func Copy ¶
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 ¶
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 ¶
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.