testmark-go

write.go

package testmark

import (
	"io"
	"os"
)

// Write writes the document to a writer.
func (d *Document) Write(w io.Writer) error {
	_, err := w.Write(d.original)
	return err
}

// WriteFile writes the document to a file.
func (d *Document) WriteFile(filename string) error {
	f, err := os.Create(filename)
	if err != nil {
		return err
	}
	defer f.Close()
	return d.Write(f)
}

// String returns the document as a string.
func (d *Document) String() string {
	return string(d.original)
}

// Bytes returns a copy of the document bytes.
func (d *Document) Bytes() []byte {
	body := make([]byte, len(d.original))
	copy(body, d.original)
	return body
}

v2/write.go · 649 B · 13b63c6f85