func findFileMarker(data []byte) (before []byte, name string, after []byte) {
	var i int
	for {
		if name, after = isMarker(data[i:]); name != "" {
			return data[:i], name, after
		}
		j := bytes.Index(data[i:], newlineMarker)
		if j < 0 {
			return fixNL(data), "", nil
		}
		i += j + 1  
	}
}
findFileMarker finds the next file marker in data,
extracts the file name, and returns the data before the marker,
the file name, and the data after the marker.
If there is no next marker, findFileMarker returns before = fixNL(data), name = "", after = nil.
package txtar
import (
	"bytes"
	"errors"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"unicode/utf8"
)
type Archive struct {
	Comment []byte
	Files   []File
}
type File struct {
	Name string  
	Data []byte  
}
func Format(a *Archive) []byte {
	var buf bytes.Buffer
	buf.Write(fixNL(a.Comment))
	for _, f := range a.Files {
		fmt.Fprintf(&buf, "-- %s --\n", f.Name)
		buf.Write(fixNL(f.Data))
	}
	return buf.Bytes()
}
func ParseFile(file string) (*Archive, error) {
	data, err := ioutil.ReadFile(file)
	if err != nil {
		return nil, err
	}
	return Parse(data), nil
}
func Parse(data []byte) *Archive {
	a := new(Archive)
	var name string
	a.Comment, name, data = findFileMarker(data)
	for name != "" {
		f := File{name, nil}
		f.Data, name, data = findFileMarker(data)
		a.Files = append(a.Files, f)
	}
	return a
}
func NeedsQuote(data []byte) bool {
	_, _, after := findFileMarker(data)
	return after != nil
}
func Quote(data []byte) ([]byte, error) {
	if len(data) == 0 {
		return nil, nil
	}
	if data[len(data)-1] != '\n' {
		return nil, errors.New("data has no final newline")
	}
	if !utf8.Valid(data) {
		return nil, fmt.Errorf("data contains non-UTF-8 characters")
	}
	var nd []byte
	prev := byte('\n')
	for _, b := range data {
		if prev == '\n' {
			nd = append(nd, '>')
		}
		nd = append(nd, b)
		prev = b
	}
	return nd, nil
}
func Unquote(data []byte) ([]byte, error) {
	if len(data) == 0 {
		return nil, nil
	}
	if data[0] != '>' || data[len(data)-1] != '\n' {
		return nil, errors.New("data does not appear to be quoted")
	}
	data = bytes.Replace(data, []byte("\n>"), []byte("\n"), -1)
	data = bytes.TrimPrefix(data, []byte(">"))
	return data, nil
}
var (
	newlineMarker = []byte("\n-- ")
	marker        = []byte("-- ")
	markerEnd     = []byte(" --")
)